Created
August 26, 2013 21:06
-
-
Save exarkun/6346658 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ISimplerRequest(Interface): | |
| method = Attribute("A C{str} giving the HTTP method that was used.") | |
| uri = Attribute( | |
| "A C{str} giving the full encoded URI which was requested (including " | |
| "query arguments).") | |
| requestHeaders = Attribute( | |
| "A L{http_headers.Headers} instance giving all received HTTP request " | |
| "headers.") | |
| content = Attribute( | |
| "A file-like object giving the request body. This may be a file on " | |
| "disk, a C{StringIO}, or some other type. The implementation is free " | |
| "to decide on a per-request basis.") | |
| responseHeaders = Attribute( | |
| "A L{http_headers.Headers} instance holding all HTTP response " | |
| "headers to be sent.") | |
| def getHost(): | |
| """ | |
| Get my originally requesting transport's host. | |
| @return: An L{IAddress<twisted.internet.interfaces.IAddress>}. | |
| """ | |
| def setHost(host, port, ssl=0): | |
| """ | |
| 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) | |
| """ | |
| def isSecure(): | |
| """ | |
| Return True if this request is using a secure transport. | |
| 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 | |
| @rtype: C{bool} | |
| """ | |
| def setResponseCode(code, message=None): | |
| """ | |
| Set the HTTP response code. | |
| """ | |
| def write(data): | |
| """ | |
| 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. | |
| """ | |
| def finish(): | |
| """ | |
| Indicate that the response to this request is complete. | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment