API: aj.http

class aj.http.CGIFieldStorage(fp=None, headers=None, outerboundary=b'', environ=environ({'READTHEDOCS_VIRTUALENV_PATH': '/home/docs/checkouts/readthedocs.org/user_builds/ajenti2/envs/latest', 'READTHEDOCS_CANONICAL_URL': 'http://docs.ajenti.org/en/latest/', 'RTD_PYTHON_VERSION_35': '3.5.10', 'HOSTNAME': 'build-21790423-project-27581-ajenti2', 'RTD_PYTHON_VERSION_27': '2.7.18', 'RTD_PYTHON_VERSION_36': '3.6.12', 'RTD_PYTHON_VERSION_37': '3.7.9', 'APPDIR': '/app', 'RTD_PYTHON_VERSION_38': '3.8.6', 'READTHEDOCS_GIT_CLONE_URL': 'https://github.com/ajenti/ajenti', 'HOME': '/home/docs', 'RTD_SETUPTOOLS_VERSION': '45.1.0', 'NO_COLOR': '1', 'READTHEDOCS': 'True', 'RTD_PYPY_VERSION_35': 'pypy3.5-7.0.0', 'READTHEDOCS_PROJECT': 'ajenti2', 'READTHEDOCS_OUTPUT': '/home/docs/checkouts/readthedocs.org/user_builds/ajenti2/checkouts/latest/_readthedocs/', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/ajenti2/envs/latest/bin:/home/docs/.pyenv/shims:/home/docs/.pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/docs/.conda/bin:/home/docs/.pyenv/bin:/home/docs/.conda/bin:/home/docs/.pyenv/bin', 'READTHEDOCS_VERSION_TYPE': 'branch', 'RTD_PIP_VERSION': '20.0.1', 'LANG': 'C.UTF-8', 'READTHEDOCS_LANGUAGE': 'en', 'DEBIAN_FRONTEND': 'noninteractive', 'READTHEDOCS_GIT_COMMIT_HASH': '0dae5b9f3f29b1204d14beebaa47b3aad2e80b0f', 'READTHEDOCS_VERSION_NAME': 'latest', 'RTD_VIRTUALENV_VERSION': '16.7.9', 'RTD_CONDA_VERSION': '4.6.14', 'READTHEDOCS_VERSION': 'latest', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/ajenti2/checkouts/latest/docs/source', 'PYENV_ROOT': '/home/docs/.pyenv', 'READTHEDOCS_GIT_IDENTIFIER': 'master', 'DOCUTILSCONFIG': '/home/docs/checkouts/readthedocs.org/user_builds/ajenti2/checkouts/latest/docs/source/docutils.conf'}), keep_blank_values=0, strict_parsing=0, limit=None, encoding='utf-8', errors='replace', max_num_fields=None)[source]
make_file(binary=None)[source]

Always open a tempfile as binary

class aj.http.HttpContext(env, start_response=None)[source]

Instance of HttpContext is passed to all HTTP handler methods

env

WSGI environment dict

path

Path segment of the URL

method

Request method

headers

List of HTTP response headers

body

Request body

response_ready

Indicates whether a HTTP response has already been submitted in this context

query

HTTP query parameters

add_header(key, value)[source]

Adds a given HTTP header to the response

Parameters:
  • key (str) – header name
  • value (str) – header value
classmethod deserialize(data)[source]
dump_env()[source]
fallthrough(handler)[source]

Executes a handler in this context

Returns:handler-supplied output
file(path, stream=False, inline=False, name=None)[source]

Returns a GZip compressed response with content of file located in path and correct headers

get_cleaned_env()[source]
gzip(content, compression=6)[source]

Returns a GZip compressed response with given content and correct headers

Parameters:compression (int) – compression level from 0 to 9
Return type:str
json_body()[source]
redirect(location)[source]

Returns a HTTP 302 Found redirect response with given location

remove_header(key)[source]

Removed a given HTTP header from the response

Parameters:key (str) – header name
respond(status)[source]

Creates a response with given HTTP status line

respond_forbidden()[source]

Returns a HTTP 403 Forbidden response

respond_not_found()[source]

Returns a HTTP 404 Not Found response

respond_ok()[source]

Creates a HTTP 200 OK response

respond_server_error()[source]

Returns a HTTP 500 Server Error response

respond_unauthenticated()[source]

Returns a HTTP 401 Unauthenticated response

run_response()[source]

Finalizes the response and runs WSGI’s start_response().

serialize()[source]
class aj.http.HttpMiddlewareAggregator(stack)[source]

Stacks multiple HTTP handlers together in a middleware fashion.

Parameters:stack (list(aj.api.http.BaseHttpHandler)) – handler list
handle(http_context)[source]

Should create a HTTP response in the given http_context and return the plain output

Parameters:http_context (aj.http.HttpContext) – HTTP context
class aj.http.HttpRoot(handler)[source]

A root WSGI middleware object that creates the HttpContext and dispatches it to an HTTP handler.

Parameters:handler (aj.api.http.BaseHttpHandler) – next middleware handler
dispatch(env, start_response)[source]

Dispatches the WSGI request


Comments

comments powered by Disqus