HTTPRequest

HTTP requests

class HTTPRequest.HTTPRequest(requestDict=None)

Bases: Request

The base class for HTTP requests.

__init__(requestDict=None)

Initialize the request.

Subclasses are responsible for invoking super and initializing self._time.

accept(which=None)

Return preferences as requested by the user agent.

The accepted preferences are returned as a list of codes in the same order as they appeared in the header. In other words, the explicit weighting criteria are ignored.

If you do not define otherwise which preferences you are interested in (‘language’, ‘charset’, ‘encoding’), by default you will get the user preferences for the content types.

clearTransaction()
contextName()

Return the name of the context of this request.

This isn’t necessarily the same as the name of the directory containing the context.

contextPath()

Return the portion of the URI that is the context of the request.

cookie(name, default=<class 'MiscUtils.NoDefault'>)

Return the value of the specified cookie.

cookies()

Return a dict of all cookies the client sent with this request.

delField(name)
environ()

Get the environment for the request.

extraURLPath()

Return additional path components in the URL.

Only works if the Application.config setting “ExtraPathInfo” is set to true; otherwise you will get a page not found error.

field(name, default=<class 'MiscUtils.NoDefault'>)
fieldStorage()
fields()
hasCookie(name)

Return whether a cookie with the given name exists.

hasField(name)
hasValue(name)

Check whether there is a value with the given name.

hostAndPort()

Return the hostname and port part from the URL of this request.

htmlInfo()

Return a single HTML string that represents info().

Useful for inspecting objects via web browsers.

info()

Return request info.

Return a list of tuples where each tuple has a key/label (a string) and a value (any kind of object).

Values are typically atomic values such as numbers and strings or another list of tuples in the same fashion. This is for debugging only.

input()

Return a file-style object that the contents can be read from.

isSecure()

Check whether this is a HTTPS connection.

isSessionExpired()

Return whether the request originally had an expired session ID.

Only works if the Application.config setting “IgnoreInvalidSession” is set to true; otherwise you get a canned error page on an invalid session, so your servlet never gets processed.

localAddress()

Get local address.

Returns a string containing the Internet Protocol (IP) address of the local host (e.g., the server) that received the request.

static localName()

Get local name.

Returns the fully qualified name of the local host (e.g., the server) that received the request.

localPort()

Get local port.

Returns the port of the local host (e.g., the server) that received the request.

method()

Return the HTTP request method (in all uppercase).

Typically from the set GET, POST, PUT, DELETE, OPTIONS and TRACE.

originalContextName()

Return the name of the original context before any forwarding.

originalServlet()

Get original servlet before any forwarding.

originalURI()

Get URI of the original servlet before any forwarding.

originalURLPath()

Get URL path of the original servlet before any forwarding.

parent()

Get the servlet that passed this request to us, if any.

parents()

Get the list of all previous servlets.

pathInfo()

Return any extra path information as sent by the client.

This is anything after the servlet name but before the query string. Equivalent to the CGI variable PATH_INFO.

pathTranslated()

Return extra path information translated as file system path.

This is the same as pathInfo() but translated to the file system. Equivalent to the CGI variable PATH_TRANSLATED.

pop()

Pop URL path and servlet from the stack, returning the servlet.

previousContextName()

Get the previous context name, if any.

previousContextNames()

Get the list of all previous context names.

previousServlet()

Get the servlet that passed this request to us, if any.

previousServlets()

Get the list of all previous servlets.

previousURI()

Get the previous URI, if any.

previousURIs()

Get the list of all previous URIs.

previousURLPath()

Get the previous URL path, if any.

previousURLPaths()

Get the list of all previous URL paths.

protocol()

Return the name and version of the protocol.

push(servlet, url=None)

Push servlet and URL path on a stack, setting a new URL.

queryString()

Return the query string portion of the URL for this request.

Equivalent to the CGI variable QUERY_STRING.

rawInput(rewind=False)

Get the raw input from the request.

This gives you a file-like object for the data that was sent with the request (e.g., the body of a POST request, or the document uploaded in a PUT request).

The file might not be rewound to the beginning if there was valid, form-encoded POST data. Pass rewind=True if you want to be sure you get the entire body of the request.

remoteAddress()

Return a string containing the IP address of the client.

remoteName()

Return the fully qualified name of the client that sent the request.

Returns the IP address of the client if the name cannot be determined.

remoteUser()

Always returns None since authentication is not yet supported.

Take from CGI variable REMOTE_USER.

requestID()

Return the request ID.

The request ID is a serial number unique to this request (at least unique for one run of the Application).

responseClass()

Get the corresponding response class.

scheme()

Return the URI scheme of the request (http or https).

scriptFileName()

Return the filesystem path of the WSGI script.

Equivalent to the CGI variable SCRIPT_FILENAME.

scriptName()

Return the name of the WSGI script as it appears in the URL.

Example: ‘/Webware’ Does not reflect redirection by the web server. Equivalent to the CGI variable SCRIPT_NAME.

serverDictionary()

Return a dictionary with the data the web server gave us.

This data includes HTTP_HOST and HTTP_USER_AGENT, for example.

serverPath()

Return the web server URL path of this request.

This is the URL that was actually received by the web server before any rewriting took place.

Same as serverURL, but without scheme and host.

serverPathDir()

Return the directory of the web server URL path.

Same as serverPath, but removes the actual page.

serverSideContextPath(path=None)

Return the absolute server-side path of the context of this request.

If the optional path is passed in, then it is joined with the server side context directory to form a path relative to the object.

This directory could be different from the result of serverSidePath() if the request is in a subdirectory of the main context directory.

serverSidePath(path=None)

Return the absolute server-side path of the request.

If the optional path is passed in, then it is joined with the server side directory to form a path relative to the object.

serverURL(canonical=False)

Return the full Internet path to this request.

This is the URL that was actually received by the web server before any rewriting took place. If canonical is set to true, then the canonical hostname of the server is used if possible.

The path is returned without any extra path info or query strings, i.e. https://www.my.own.host.com:8080/Webware/TestPage.py

serverURLDir()

Return the directory of the URL in full Internet form.

Same as serverURL, but removes the actual page.

servlet()

Get current servlet for this request.

servletPath()

Return the base URL for the servlets, sans host.

This is useful in cases when you are constructing URLs. See Testing/Main.py for an example use.

Roughly equivalent to the CGI variable SCRIPT_NAME, but reflects redirection by the web server.

servletPathFromSiteRoot()

Return the “servlet path” of this servlet relative to the siteRoot.

In other words, everything after the name of the context (if present). If you append this to the result of self.siteRoot() you get back to the current servlet. This is useful for saving the path to the current servlet in a database, for example.

servletURI()

Return servlet URI without any query strings or extra path info.

session()

Return the session associated with this request.

The session is either as specified by sessionId() or newly created. This is a convenience for transaction.session()

sessionId()

Return a string with the session ID specified by the client.

Returns None if there is no session ID.

setField(name, value)
setSessionExpired(sessionExpired)
setSessionId(sessionID, force=False)

Set the session ID.

This needs to be called _before_ attempting to use the session. This would be useful if the session ID is being passed in through unusual means, for example via a field in an XML-RPC request.

Pass in force=True if you want to force this session ID to be used even if the session doesn’t exist. This would be useful in unusual circumstances where the client is responsible for creating the unique session ID rather than the server. Be sure to use only legal filename characters in the session ID – 0-9, a-z, A-Z, _, -, and . are OK but everything else will be rejected, as will identifiers longer than 80 characters. (Without passing in force=True, a random session ID will be generated if that session ID isn’t already present in the session store.)

setTransaction(trans)

Set a transaction container.

setURLPath(path)

Set the URL path of the request.

There is rarely a need to do this. Proceed with caution.

siteRoot()

Return the relative URL path of the home location.

This includes all URL path components necessary to get back home from the current location.

Examples:

‘’ ‘../’ ‘../../’

You can use this as a prefix to a URL that you know is based off the home location. Any time you are in a servlet that may have been forwarded to from another servlet at a different level, you should prefix your URL’s with this. That is, if servlet “Foo/Bar” forwards to “Qux”, then the qux servlet should use siteRoot() to construct all links to avoid broken links. This works properly because this method computes the path based on the _original_ servlet, not the location of the servlet that you have forwarded to.

siteRootFromCurrentServlet()

Return relative URL path to home seen from the current servlet.

This includes all URL path components necessary to get back home from the current servlet (not from the original request).

Similar to siteRoot() but instead, it returns the site root relative to the _current_ servlet, not the _original_ servlet.

time()

Return the time that the request was received.

timeStamp()

Return time() as human readable string for logging and debugging.

transaction()

Get the transaction container.

uri()

Return the URI for this request (everything after the host name).

This is the URL that was actually received by the web server before any rewriting took place, including the query string. Equivalent to the CGI variable REQUEST_URI.

uriWebwareRoot()

Return relative URL path of the Webware root location.

urlPath()

Get the URL path relative to the mount point, without query string.

This is actually the same as pathInfo().

For example, https://host/Webware/Context/Servlet?x=1 yields ‘/Context/Servlet’.

urlPathDir()

Same as urlPath, but only gives the directory.

For example, https://host/Webware/Context/Servlet?x=1 yields ‘/Context’.

value(name, default=<class 'MiscUtils.NoDefault'>)

Return the value with the given name.

Values are fields or cookies. Use this method when you’re field/cookie agnostic.

writeExceptionReport(handler)
HTTPRequest.htmlInfo(info)

Return a single HTML string that represents the info structure.

Useful for inspecting objects via web browsers.