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

list – 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.

app

str – 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.

app_uri

str – Absolute URI to WSGI Application.

id

str – Unique request identifier.

env

str – Reference to the WSGI environ from the server.

cache_control

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

context_domain

str – The domain in which the request is currently scoped.

context_interface

str – The interface in which the request is currently scoped.

context_region

str – The region in which the request is currently scoped.

context_tenant_id

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

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

int – Maximum age, as specified for Cache control.

method

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

route

str – 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.

tag

str – Route tag, used by policies to apply rules.

forwarded_app_uri

str – Absolute original URI to WSGI Application.

uri

str – The fully-qualified absolute URI for the request.

forwarded_uri

str – URI for proxied requests.

relative_uri

str – The path and query string portion.

forwarded

list – 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

scheme

str – 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.

forwarded_scheme

str – 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.

host

str – 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.

forwarded_host

str – 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.

port

int – 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).

netloc

str – 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).

subdomain

str – 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.

remote_addr

str – 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.

query_string

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

query_params

dict – 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.

relative_resource_uri

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

content_type

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

content_length

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

stream

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

json

object – JSON Payload as object.

form

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

form_dict

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.

form_array

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

form_json

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

date

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

auth

str – Value of the Authorization header, or None if missing.

user_agent

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

referer

str – Value of the Referer header, or None if missing.

expect

str – Value of the Expect header, or None if missing.

if_match

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

if_none_match

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

if_modified_since

datetime – Value of the If-Modified-Since header,

if_unmodified_since

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

if_range

str – Value of the If-Range header, or None.

is_ajax

bool – Whether or not Request is an AJAX request.

range

tuple of int – 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”.

range_unit

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

static

str – Cached value of the Applications static path.

session

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

user_token

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

scope_token

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

cookies

dict – A dict of name/value cookie pairs.

is_bot

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

is_mobile

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

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.

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.