Request Headers

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.

Content Types

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.

Content Preferences

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.

Other Headers

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.

WebStack API - Accessing Header Information

Transaction objects provide the following methods to access request header information:

get_headers
This returns a dictionary mapping header names to single string values.
get_header_values
Given a header name as parameter, this method returns a list of string values associated with that name.
get_content_type
This returns a content type object (typically WebStack.Generic.ContentType) describing the incoming request body content.
get_content_languages
This returns a list of language identifiers, in descending order of preference, indicating in which languages the sender of the request would prefer to receive information.
get_content_charsets
This returns a list of character set identifiers, in descending order of preference, indicating in which character sets the sender of the request would prefer to receive information.

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.