Powered by Tachyonic Project Luxon Framework v0.0.0

Luxon Framework for rapid application development. (luxon)

Version

WSGI Request Class

Child Class of Luxon’s RequestBase Class.

class luxon.core.handlers.wsgi.request.Request(env, start_response)[source]

Represents a clients HTTP request.

Parameters:
  • env (dict) – A WSGI environment dict passed in from the server. As per PEP-3333.
  • start_response (function) – callback function supplied by the server which takes the HTTP status and headers as arguments.
access_hops

IP address of the original client, as well as any addresses of proxies fronting the WSGI server.

The following request headers are checked, in order of preference, to determine the addresses:

  • Forwarded
  • X-Forwarded-For
  • X-Real-IP

If none of these headers are available, the value of remote_addr attribute is returned.

In RFC 7239, the access route may contain “unknown” and obfuscated identifiers, in addition to IPv4 and IPv6 addresses

Headers can be forged by any client or proxy. Use this property with caution and validate all values before using them. Do not rely on the access route to authorize requests.

Type:list
app

The initial portion of the request URI’s path that corresponds to the applicationm so that the application knows its virtual location. This could be an empty string, if the application corresponds to the root of the server.

Reference to the ‘SCRIPT_NAME’ environ variable defined by PEP-3333.

Type:str
app_uri

Absolute URI to WSGI Application.

Type:str
id

Unique request identifier.

Type:str
env

Reference to the WSGI environ from the server.

Type:str
cache_control

A luxon.utils.http.CacheControl obj populated from the Request Headers.

Type:obj
context_domain

The domain in which the request is currently scoped.

Type:str
context_interface

The interface in which the request is currently scoped.

Type:str
context_region

The region in which the request is currently scoped.

Type:str
context_tenant_id

The uuid of the Tenant in which the request is currently scoped.

Type:str
log

Dictionary/Property object to hold any data about the request which is specific to your app for appending to logs. (e.g. USERNAME)

max_age

Maximum age, as specified for Cache control.

Type:int
method

HTTP method requested (e.g., ‘GET’, ‘POST’, etc.) May be set to new value by ‘process’ middleware method in order to influence routing.

Type:str
route

Path portion of the request URI. May be set to a new value by a ‘process’ middleware method in order to influence routing. Does not include the query string.

Type:str
tag

Route tag, used by policies to apply rules.

Type:str
forwarded_app_uri

Absolute original URI to WSGI Application.

Type:str
uri

The fully-qualified absolute URI for the request.

Type:str
forwarded_uri

URI for proxied requests.

Type:str
relative_uri

The path and query string portion.

Type:str
forwarded

Value of the Forwarded header, as a parsed list of luxon.core.http.headers.ForwardedElement objects or if the header is missing None

Reference RFC 7239, Section 4

Type:list
scheme

URL scheme used in the request. Either ‘http’ or ‘https’. If the request was proxied, the scheme may not match what was originally requested by the client. For this ‘forwarded_scheme’ can be used used instead.

Type:str
forwarded_scheme

Original URL scheme requested by the user agent, if the request as proxied. Either ‘http’ or https’.

The following request headers are checked, in order of preference to determine the value:

  • Forwarded
  • X-Forwarded-For

if none of these headers are availible or does not contain a ‘proto’ parameter in the first hop, the value of the ‘scheme’ is returned.

Reference RFC 7239, Section 1.

Type:str
host

Only host in request header field. The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource.

Use other methods such as port, netloc to include the port.

Type:str
forwarded_host

Original host request header as received by the first proxy in front of the application server.

The following request headers are checked, in order of preference, to determine the forwarded scheme:

  • Forwarded
  • X-Forwarded-Host

If none of the above headers are available, or if the Forwarded header is available but the host parameter is not included in the first hop, the value of host is returned instead.

Reverse proxies are often configured to set the Host header directly to the one that was originally requested by the user agent; in that case, using host is sufficient.

Refer RFC 7239, Section 4.

Type:str
port

Port used for the request. If the request URI does not specify a port, the default one for the given schema is returned (80 for HTTP and 443 for HTTPS).

Type:int
netloc

Returns the ‘host:port’ portion of the request URL. The port may be ommitted if it is the default one for the URL’s schema (80 for HTTP and 443 for HTTPS).

Type:str
subdomain

Leftmost (i.e., most specific) subdomain from the hostname. If only a single domain name is given, subdomain will be None.

Note

If the hostname in the request is an IP address, the value for subdomain is undefined.

Type:str
remote_addr

IP address of the closest client or proxy to the WSGI server.

This property is determined by the value of ‘REMOTE_ADDR’ in the WSGI environment dict. Since this address is not derived from an HTTP header, clients and proxies can not forge it.

If your application is behind one or more reverse proxies, you can use ‘access_hops’ attribute to retrieve the real IP address of the client.

Type:str
query_string

Query string portion of the request URI, without the preceding ‘?’ character.

Type:str
query_params

The mapping of request query parameter names to their values. Where the parameter appears multiple times in the query string, the value mapped to that parameter key will be a list of all the values in the order seen.

Type:dict
relative_resource_uri

Portion of the URI that comprising of the app and route.

Type:str
content_type

Value of the Content-Type header, or None if the header is missing.

Type:str
content_length

Value of the Content-Length header converted to an ‘int’ or None if the header is missing.

Type:int
stream

File-like input object for reading the body of the request.

json

JSON Payload as object.

Type:object
form

cgi.FieldStorage() To get at submitted form data. As per Common Gateway Interface support provided by Python natively.

form_dict

Generated dictionary of form data submitted with field names as keys and values provided as either str, bytes or list. List values are for when multiple values exist for the same form field.

Type:dict
form_array

Not Implemented yet, will provide ability to get a list of dicts providing providing form data similiar to PHP use case.

Type:list
form_json

Provides form and all its submitted data as json serialized string.

Type:str
date

Value of the Date Header. The header value is assumed to conform to RFC 1123.

Type:datetime
auth

Value of the Authorization header, or None if missing.

Type:str
user_agent

Value of the User-Agent header, or None if missing.

Type:str
referer

Value of the Referer header, or None if missing.

Type:str
expect

Value of the Expect header, or None if missing.

Type:str
if_match

Value of the If-Match header, or None if missing.

Type:str
if_none_match

Value of the If-None-Match header, or None if missing.

Type:str
if_modified_since

Value of the If-Modified-Since header,

Type:datetime
if_unmodified_since

Value of the If-Unmodified-Since header, or None if missing.

Type:datetime
if_range

Value of the If-Range header, or None.

Type:str
is_ajax

Whether or not Request is an AJAX request.

Type:bool
range

A 2-member ‘tuple’ parsed from the value of the Range header.

The two members correspond to the first and last byte positions of the requested resource, inclusive. Negative indices indicate offset from the end of the resource, where -1 is the last byte, -2 is the second-to-last byte, and so forth.

None continues would result in an HTTPBadRequest exception when the attribute is accessed. e.g. “bytes=0-0,-1”.

Type:tuple of int
range_unit

Unit of the range parsed from the value of the Range header, or None if the header is missing.

Type:str
static

Cached value of the Applications static path.

Type:str
session

Cached luxon.core.session.Session obj initialized with session backend class specified in the settings.ini file.

Type:obj
user_token

The value of the token for the user’s current request.

Type:str
scope_token

The value of the scoped token for the user’s current scoped request.

Type:str
cookies

A dict of name/value cookie pairs.

Type:dict
is_bot

If user-agent is detected as ‘Bot’ e.g Google Bot

Type:bool
is_mobile

If user-agent is detected as mobile. e.g. Iphone

Type:bool
get_all_files()[source]

Get multiple files for the form.

Returns an empty list if no files. It’s guaranteed to return a list.

Returns:Sequence of FileObject Instances.
Return type:tuple
get_file(field, required=False)[source]

Get file for the given field name in form.

This method always returns only one value associated with form field name. The method returns only the first value in case that more values were posted under such name. Please note that the order in which the values are received may vary from browser to browser and should not be counted on. If no such form field or value exists then the method returns the value specified by the optional parameter default. This parameter defaults to None if not specified.

Parameters:

field (str) – Form field name.

Keyword Arguments:
 

required (bool) – Set to ‘True’ to raise ‘HTTPMissingParam’ instead of returning gracefully when field is not found (default ‘False’).

Returns:

FileObject Instance.

Return type:

tuple

Raises:
  • HTTPMissinParam – The parameter was not found in the request, but it was required.
  • HTTPUnsupportedMediaType – Expected payload.
get_files(field, required=False)[source]

Get multiple files for the given field name in form.

Returns an empty list if the file doesn’t exist. It’s guaranteed to return a list unless the field is required as per keyword args.

Parameters:

field (str) – Form field name.

Keyword Arguments:
 

required (bool) – Set to ‘True’ to raise ‘HTTPMissingParam’ instead of returning gracefully when field is not found (default ‘False’).

Returns:

Sequence of FileObject Instances.

Return type:

tuple

Raises:
  • HTTPMissinParam – The parameter was not found in the request, but it was required.
  • HTTPUnsupportedMediaType – Expected payload.
get_first(field, required=False, default=None)[source]

Get the value for the given field name in form.

This method always returns only one value associated with form field name. The method returns only the first value in case that more values were posted under such name. Please note that the order in which the values are received may vary from browser to browser and should not be counted on. If no such form field or value exists then the method returns the value specified by the optional parameter default. This parameter defaults to None if not specified.

Parameters:

field (str) – Form field name.

Keyword Arguments:
 
  • required (bool) – Set to ‘True’ to raise ‘HTTPMissingParam’ instead of returning gracefully when field is not found (default ‘False’).
  • default (str) – Value to return if field is not found.
Returns:

String Value of Field.

Return type:

str

Raises:
  • HTTPMissinParam – The parameter was not found in the request, but it was required.
  • HTTPUnsupportedMediaType – Expected payload.
get_header(name, required=False, default=None)[source]

Retrieve the raw string value for the given header.

Parameters:

name (str) – Header name, case-insensitive (e.g., ‘Content-Type’)

Keyword Arguments:
 
  • required (bool) – Set to ‘True’ to raise ‘HTTPMissingHeader’ instead of returning gracefully when header is not found (default ‘False’).
  • default (any) – Value to return if the header is not found (default None).
Returns:

The value of the specified header if it exists, or the default value if the header is not found and is not required.

Return type:

str

Raises:

HTTPMissingHeader – The header was not found in the request, but it was required.

get_header_as_datetime(header, required=False, obs_date=False)[source]

Return an HTTP header with HTTP-Date values as a datetime.

Parameters:

name (str) – Header name, case-insensitive (e.g., ‘Date’)

Keyword Arguments:
 
  • required (bool) – raise HTTPBadRequest (default False)
  • obs_date (bool) – Support obs-date formats according to RFC 7231 (e.g. Sunday, 06-Nov-94 08:49:37 GMT) (default False).
Returns:

The value of the specified header if it exists,

or None if the header is not found and is not required.

Return type:

datetime

Raises:
  • HTTPBadRequest – The header was not found in the request, but it was required.
  • HttpInvalidHeader – The header contained a malformed/invalid value.
get_list(field, required=False)[source]

Get list of values for the requested field name in form.

Returns an empty list if the file doesn’t exist. It’s guaranteed to return a list unless the field is required as per keyword args.

Parameters:

field (str) – Form field name.

Keyword Arguments:
 

required (bool) – Set to ‘True’ to raise ‘HTTPMissingParam’ instead of returning gracefully when field is not found (default ‘False’).

Returns:

List of values.

Return type:

tuple

Raises:
  • HTTPMissinParam – The parameter was not found in the request, but it was required.
  • HTTPUnsupportedMediaType – Expected payload.
is_bot

Returns True if client is bot.

is_mobile

Returns True if mobile client is used.

proxy_context

Return context headers.

read(size=None)[source]

Read at most size bytes, returned as a bytes object.

Keyword Arguments:
 size (int) – Size in octets to read.
Returns:Bytes within the request payload.
Return type:bytes
Raises:HTTPUnsupportedMediaType – Expected payload.
readline(size=None)[source]

Read at most size bytes, returned as a bytes object.

Keyword Arguments:
 size (int) – Size in octets to read.
Returns:Bytes within the request payload.
Return type:bytes
Raises:HTTPUnsupportedMediaType – Expected payload.