OPSI.web2.http module¶
HyperText Transfer Protocol implementation.
The second coming.
Maintainer: U{James Y Knight <mailto:foom@fuhm.net>}
-
exception
OPSI.web2.http.
HTTPError
(codeOrResponse)¶ Bases:
exceptions.Exception
-
OPSI.web2.http.
NotModifiedResponse
(oldResponse=None)¶
-
class
OPSI.web2.http.
Request
(chanRequest, command, path, version, contentLength, headers)¶ Bases:
object
A HTTP request.
Subclasses should override the process() method to determine how the request will be processed.
@ivar method: The HTTP method that was used. @ivar uri: The full URI that was requested (includes arguments). @ivar headers: All received headers @ivar clientproto: client HTTP version @ivar stream: incoming data stream.
-
checkExpect
()¶ Ensure there are no expectations that cannot be met. Checks Expect header against self.known_expects.
-
connectionLost
(reason)¶ connection was lost
-
handleContentChunk
(data)¶ Callback from channel when a piece of data has been received. Puts the data in .stream
-
handleContentComplete
()¶ Callback from channel when all data has been received.
-
known_expects
= ('100-continue',)¶
-
process
()¶ Called by channel to let you process the request.
Can be overridden by a subclass to do something useful.
-
writeResponse
(response)¶ Write a response.
-
-
class
OPSI.web2.http.
Response
(code=None, headers=None, stream=None)¶ Bases:
object
An object representing an HTTP Response to be sent to the client.
-
code
= 200¶
-
headers
= None¶
-
stream
= None¶
-
-
OPSI.web2.http.
checkIfRange
(request, response)¶ Checks for the If-Range header, and if it exists, checks if the test passes. Returns true if the server should return partial data.
-
OPSI.web2.http.
checkPreconditions
(request, response=None, entityExists=True, etag=None, lastModified=None)¶ Check to see if this request passes the conditional checks specified by the client. May raise an HTTPError with result codes L{NOT_MODIFIED} or L{PRECONDITION_FAILED}, as appropriate.
This function is called automatically as an output filter for GET and HEAD requests. With GET/HEAD, it is not important for the precondition check to occur before doing the action, as the method is non-destructive.
However, if you are implementing other request methods, like PUT for your resource, you will need to call this after determining the etag and last-modified time of the existing resource but before actually doing the requested action. In that case,
This examines the appropriate request headers for conditionals, (If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range), compares with the etag and last and and then sets the response code as necessary.
- @param response: This should be provided for GET/HEAD methods. If
- it is specified, the etag and lastModified arguments will be retrieved automatically from the response headers and shouldn’t be separately specified. Not providing the response with a GET request may cause the emitted “Not Modified” responses to be non-conformant.
- @param entityExists: Set to False if the entity in question doesn’t
- yet exist. Necessary for PUT support with ‘If-None-Match: *‘.
@param etag: The etag of the resource to check against, or None.
- @param lastModified: The last modified date of the resource to check
- against, or None.
- @raise: HTTPError: Raised when the preconditions fail, in order to
- abort processing and emit an error page.
-
OPSI.web2.http.
parseVersion
(strversion)¶ Parse version strings of the form Protocol ‘/’ Major ‘.’ Minor. E.g. ‘HTTP/1.1’. Returns (protocol, major, minor). Will raise ValueError on bad syntax.
-
OPSI.web2.http.
splitHostPort
(scheme, hostport)¶ Split the host in “host:port” format into host and port fields. If port was not specified, use the default for the given scheme, if known. Returns a tuple of (hostname, portnumber).