Part of twisted.web.iweb View Source View In Hierarchy
Known implementations: twisted.web.server.Request
Present Since | 9.0 |
Attribute | method | A str giving the HTTP method that was used. |
Attribute | uri | A str giving the full encoded URI which was requested
(including query arguments). |
Attribute | path | A str giving the encoded query path of the request URI. |
Attribute | args | A mapping of decoded query argument names as str to
corresponding query argument values as list s of
str . For example, for a URI with
'foo=bar&foo=baz&quux=spam' for its query part,
args will be {'foo': ['bar', 'baz'], 'quux':
['spam']} . |
Attribute | received_headers | Backwards-compatibility access to requestHeaders . Use
requestHeaders instead. received_headers behaves
mostly like a dict and does not provide access to all header
values. |
Attribute | requestHeaders | A http_headers.Headers
instance giving all received HTTP request headers. |
Attribute | headers | Backwards-compatibility access to responseHeaders .
UseresponseHeaders instead. headers behaves
mostly like a dict and does not provide access to all header
values nor does it allow multiple values for one header to be set. |
Attribute | responseHeaders | A http_headers.Headers
instance holding all HTTP response headers to be sent. |
Method | getHeader | Get an HTTP request header. |
Method | getCookie | Get a cookie that was sent from the network. |
Method | getAllHeaders | Return dictionary mapping the names of all received headers to the last value received for each. |
Method | getRequestHostname | Get the hostname that the user passed in to the request. |
Method | getHost | Get my originally requesting transport's host. |
Method | getClientIP | Return the IP address of the client who submitted this request. |
Method | getClient | Return the hostname of the IP address of the client who submitted this request, if possible. |
Method | getUser | Return the HTTP user sent with this request, if any. |
Method | getPassword | Return the HTTP password sent with this request, if any. |
Method | isSecure | Return True if this request is using a secure transport. |
Method | getSession | Look up the session associated with this request or create a new one if there is not one. |
Method | URLPath | |
Method | prePathURL | |
Method | rememberRootURL | Remember the currently-processed part of the URL for later recalling. |
Method | getRootURL | Get a previously-remembered URL. |
Method | finish | Indicate that the response to this request is complete. |
Method | write | Write some data to the body of the response to this request. Response headers are written the first time this method is called, after which new response headers may not be added. |
Method | addCookie | Set an outgoing HTTP cookie. |
Method | setResponseCode | Set the HTTP response code. |
Method | setHeader | Set an HTTP response header. Overrides any previously set values for this header. |
Method | redirect | Utility function that does a redirect. |
Method | setLastModified | Set the Last-Modified time for the response to this
request. |
Method | setETag | Set an entity tag for the outgoing response. |
Method | setHost | Change the host and port the request thinks it's using. |
str
to
corresponding query argument values as list
s of
str
. For example, for a URI with
'foo=bar&foo=baz&quux=spam'
for its query part,
args
will be {'foo': ['bar', 'baz'], 'quux':
['spam']}
.requestHeaders
. Use
requestHeaders
instead. received_headers
behaves
mostly like a dict
and does not provide access to all header
values.responseHeaders
.
UseresponseHeaders
instead. headers
behaves
mostly like a dict
and does not provide access to all header
values nor does it allow multiple values for one header to be set.Parameters | key | The name of the header to get the value of. (type: str ) |
Returns | The value of the specified header, or None if that header was
not present in the request. (type: str or NoneType ) |
Since this method does not return all header information,
requestHeaders.getAllRawHeaders()
may be preferred.
This will either use the Host: header (if it is available) or the host we are listening on if the header is unavailable.
Returns | the requested hostname (type: str ) |
Returns | the client IP address or None if the request was submitted
over a transport where IP addresses do not make sense. (type: str or NoneType ) |
This method is deprecated. See getClientIP
instead.
Returns | The canonical hostname of the client, as determined by performing a name
lookup on the IP address of the client. (type: NoneType or str ) |
If no user was supplied, return the empty string.
Returns | the HTTP user, if any (type: str ) |
If no password was supplied, return the empty string.
Returns | the HTTP password, if any (type: str ) |
Normally this method returns True if this request's HTTPChannel instance is using a transport that implements ISSLTransport.
This will also return True if setHost() has been called with ssl=True.
Returns | True if this request is secure (type: bool ) |
Returns | The Session
instance identified by the session cookie in the request, or the
sessionInterface component of that session if
sessionInterface is specified. |
Returns | A URLPath
instance which identifies the URL for which this request is. |
Returns | At any time during resource traversal, a str
giving an absolute URL to the most nested resource which has yet been
reached. |
In general, you should consider using sessions instead of cookies, see
twisted.web.server.Request.getSession
and the twisted.web.server.Session
class for details.
Parameters | name | The name of the header for which to set the value. (type: str ) |
value | The value to set for the named header. (type: str ) |
The request should have finish() called after this.
Last-Modified
time for the response to this
request.
If I am called more than once, I ignore attempts to set Last-Modified earlier, only replacing the Last-Modified time if it is to a later value.
If I am a conditional request, I may modify my response code to
NOT_MODIFIED
if appropriate for the time given.
Parameters | when | The last time the resource being returned was modified, in seconds since
the epoch. (type: int , long or float ) |
Returns | If I am a If-Modified-Since conditional request and the time
given is not newer than the condition, I return http.CACHED to
indicate that you should write no body. Otherwise, I return a false value. |
entity tag
for the outgoing response.
That's "entity tag" as in the HTTP/1.1 ETag
header, "used for comparing two or more entities from the same
requested resource."
If I am a conditional request, I may modify my response code to
NOT_MODIFIED
or PRECONDITION_FAILED
, if
appropriate for the tag given.
Parameters | etag | The entity tag for the resource being returned. (type: str ) |
Returns | If I am a If-None-Match conditional request and the tag
matches one in the request, I return http.CACHED to indicate
that you should write no body. Otherwise, I return a false value. |
Change the host and port the request thinks it's using.
This method is useful for working with reverse HTTP proxies (e.g. both Squid and Apache's mod_proxy can do this), when the address the HTTP client is using is different than the one we're listening on.
For example, Apache may be listening on https://www.example.com, and then forwarding requests to http://localhost:8080, but we don't want HTML produced by Twisted to say 'http://localhost:8080', they should say 'https://www.example.com', so we do:
request.setHost('www.example.com', 443, ssl=1)