Request headers are pieces of information that describe certain aspects of a request, such as:
The location and related query information is conveniently accessible through path information and request header parameter information. Other types of header information are made available through other WebStack API methods.
When a Web application sends some information in a response, it describes the content type of that information, and this is described in the "Responses and Presentation" document. However, it is also possible that information sent to the application is also described using a content type, and such details may be investigated using code similar to the following:
class MyResource:
def respond(self, trans):
content_type = trans.get_content_type() # returns a WebStack.Generic.ContentType object
Unfortunately, such information is not always provided by Web browsers.
Sometimes, Web browsers describe the kinds of information that they are willing to receive, and WebStack provides various means to query such preferences:
languages = trans.get_content_languages() # returns a list of language codes
charsets = trans.get_content_charsets() # returns a list of character set identifiers
This information permits us to send content which matches the expectations of the user, or at least the expectations of the user's software.
Various other pieces of information may be attached to the request as headers, and such information can be accessed through the general header access methods as described below. Each header has a particular name which is associated with a corresponding value.
Transaction objects provide the following methods to access request header information:
get_headers
get_header_values
get_content_type
WebStack.Generic.ContentType
) describing the incoming request body content.get_content_languages
get_content_charsets
It should be noted that the get_headers
and get_header_values
methods
present a slightly different view of the available header information,
in that only a single header value is made available through the get_headers
method for each header name, whereas get_header_values
provides potentially many values for the same header name.