fault.web

Service contexts for accepting HTTP requests.

functools
import

typing
import

weakref
import

match
import

core
import

flows
import

io
import

ri
import

http
import

_prepare_http_transports_v0
function

_prepare_http_transports_v0(ifctx, ports)

_prepare_http_transports_v1
function

_prepare_http_transports_v1(ifctx, ports)

_prepare_http_transports_v2
function

_prepare_http_transports_v2(ifctx, ports)

protocols
data

protocols = {
	'http': _prepare_http_transports_v0, # Adjustable.
	'http-1': _prepare_http_transports_v1, # Strictly 1.0/1.1 only.
	'http-2': _prepare_http_transports_v2, # Not implemented
}

Controller
class

Request execution controller for HTTP services.

Controllertransport
property
io.Transport

Controllerfrom_accept
classmethod

from_accept(Class, invp, pair)

Controller__init__
method

__init__(self, invocations, request, connect_output, connect_input, channel_id)

Controllerconnect
method
None

connect(self, channel)

Initiate the response causing headers to be sent and connect the channel as the HTTP response entity body. If channel is None, no entity body will be supplied.

Controlleraccept
method

accept(self, channel)

Connect entity body of the request to the given channel. If channel is None, any entity body sent will trigger a fault.

Controllerhttp_add_header
method
None

http_add_header(self, key, value)

Append a single header to the header sequence that will be supplied by the response.

Controlleradd_header
data

add_header = http_add_header

Controllerhttp_extend_headers
method
None

http_extend_headers(self, pairs)

Add a sequence of headers.

Controllerextend_headers
data

extend_headers = http_extend_headers

Controllerhttp_set_response
method

http_set_response(self, code, descr, length)

Assign the status of the response and designate the transfer encoding. Excepting length, all parameters must be bytes instances; this is intended to emphasize that the fields are being directly inserted into the wire.

If cotype is None, neither Content-Length nor Transfer-Encoding will be appended to the headers.

If cotype is not None and length is None, chunked transfer encoding will be used. If cotype is not None and length is an integer, Content-Length will be provided.

Controllerset_response
data

set_response = http_set_response

Controllerhttp_continue
method

http_continue(self, headers)

Emit a 100 continue response with the given headers. Emitting a continuation after a non-100 response has been sent will fault the Transaction.

Controllerhttp_continueEngineering

Currently, the HTTP implementation presumes one response per transaction which is in conflict with HTTP/1.1's CONTINUE.

Controllerhttp_redirect
method

http_redirect(self, location)

Location header redirect using a 301-MOVED PERMANENTLY response.

Controller_http_content_headers
method

_http_content_headers(self, cotype, length)

Define the type and length of the entity body to be sent.

Controllerhttp_dispatch_output
method

http_dispatch_output(self, channel)

Dispatch the given channel using a new fault.kernel.io.Transfer instance into invocations' fault.kernel.io.Transport transaction.

Controllerhttp_iterate_output
method

http_iterate_output(self, iterator)

Construct a Flow consisting of a single fault.kernel.flows.Iterate instance used to stream output to the connection protocol state.

The fault.kernel.io.Transfer transaction will be dispatched into the fault.kernel.io.Transport supporting the connection to the remote peer.

Controllerhttp_write_output
method

http_write_output(self, cotype, data)

Send the given data to the remote end with the given content type, cotype. If other headers are desired, they must be configured before running this method.

Controllerhttp_write_text
method

http_write_text(self, string)

Send the given data to the remote end with the given mime type. If other headers are desired, they must be configured before running this method.

Controllerhttp_read_file_into_output
method

http_read_file_into_output(self, route, cotype)

Send the file referenced by route to the remote end as the (HTTP) entity body.

Controllerhttp_read_file_into_outputParameters

self

Undocumented.

route

Route instance selecting the file.

cotype

The content type to designate in the response.

Controllerhttp_send_file_head
method

http_send_file_head(self, route, cotype)

Send the file referenced by route to the remote end as the (HTTP) entity body.

Controllerhttp_send_file_headParameters

self

Undocumented.

route

Route instance selecting the file.

cotype

The content type to designate in the response.

Controllerhttp_read_input_into_buffer
method

http_read_input_into_buffer(self, callback, *args)

Connect the input Flow to a buffer that executes the given callback when the entity body has been transferred.

Controllerhttp_ignore_input
method

http_ignore_input(self)

Connect the given input to a transfer that discards events.

Network
class

System Context for managing a set of Host instances. Provides grouping for hosts that share the same system network interface.

NetworkProperties

http_default_host

The default HTTP Host; the Host to select in cases where no Host is designated by a request.

Networkhttp_default_host
data

http_default_host = None

Network__init__
method

__init__(self)

Networknet_dispatch
method

net_dispatch(self, host)

Networknet_select_host
method

net_select_host(self, name)

Networknet_accept
method

net_accept(self, invp)

Route the protocol transactions to the designated host. This only enqueues the invocation for subsequent execution.

Networkactuate
method

actuate(self)

Networkterminate
method

terminate(self)

Networkxact_void
method

xact_void(self, final)

Partition
class

Base class for host applications.

PartitionProperties

part_path

The absolute (URI) path used to reach the partition. For application servers, this is normally '/'.

part_argv

The arguments that were configured with the partition.

Partition__init__
method

__init__(self, path)

Partitionstructure
method

structure(self)

Partitionactuate
method

actuate(self)

Partitionpart_accept
method

part_accept(self, invp)

Allocate a sequence of controllers and process them using part_select.

Partitionpart_select
method

part_select(self, ctl)

Partitionterminate
method

terminate(self)

Partitionxact_void
method

xact_void(self, final)

Files
class

Read-only filesystem union for serving local files.

Filespart_dispatched
method

part_dispatched(self, argv)

Filespart_select
method

part_select(self, ctl)

Host
class

An HTTP Host interface for managing routing of service connections, and handling the representation of error cases.

HostProperties

h_names

The set hostnames that this host can facilitate. The object can be an arbitrary container in order to match patterns as well.

h_canonical

The first name given to h_update_names. None if no names were given and the name should be inherited from requests.

h_root

The root of the host's path as a fault.context.match.SubsequenceScan. This is the initial path of the router in order to allow "mounts" at arbitrary positions. Built from requisite prefixes.

h_allowed_methods

Method restrictions for the host. None if not restricted.

h_headers

Headers added to every response routed to this host.

HostEngineering

While proper caching should be handled by a proxy, caching of "constants" should be performed here as well. A constant would be a resource that is designated as being the only possible version when given the same path. Constants would be shared across forks using a mmap region initialized by a parent process.

Hoststrcache
staticmethod

strcache(obj)

Cache for encoded identifiers often used with a host.

Hostdescriptioncache
staticmethod

descriptioncache(obj)

Hosth_defaults
data

h_defaults = {
	'h_options': (),
	'h_allowed_methods': frozenset({
		b'GET', b'HEAD', b'POST', b'PUT',
		b'PATCH', b'DELETE', b'OPTIONS'
	}),
}

Hosth_canonical
data

h_canonical = None

Hosth_names
data

h_names = None

Hosth_options
data

h_options = None

Hosth_allowed_methods
data

h_allowed_methods = h_defaults['h_allowed_methods']

Hosth_redirects
data

h_redirects = None

Hosth_headers
data

h_headers = ()

Hostactuate
method

actuate(self)

Hosth_enable_options
method

h_enable_options(self, *option_identifiers)

Hosth_disable_options
method

h_disable_options(self, *option_identifiers)

Hosth_set_headers
method

h_set_headers(self, headers)

Hosth_update_names
method

h_update_names(self, *names)

Modify the host names that this interface responds to.

Host__init__
method

__init__(self, partitions)

Hosth_set_redirects
method

h_set_redirects(self, target, origins)

Hosth_clear_redirects
method

h_clear_redirects(self)

Hosth_configure
method

h_configure(self, partitions)

Configure and dispatch the host's partitions.

Hosth_connect
method

h_connect(self, partition)

Add the given partition to the host.

Hosth_disconnect
method

h_disconnect(self, partition)

Terminate and remove the partition identified by its path.

Hoststructure
method

structure(self)

Hosth_options_request
method

h_options_request(self, ctl)

Handle a request for OPTIONS * HTTP/x.x. Individual Resources may support an OPTIONS request as well.

Hosth_error
method

h_error(self, ctl, code, exc)

Host error handler. By default, emits an XML document with an assigned stylesheet that can be retrieved for formatting the error. Additional error data may by injected into the document in order to provide application-level error information.

Given the details about an HTTP error message and the corresponding fault.web.http.IO, emit the rendered error to the client.

Hosth_fallback
method

h_fallback(self, ctl)

Method called when no prefix matches the request.

Provided for subclasses in order to override the usual 404.

Hosth_route
method

h_route(self, ctl)

Route the request to the identified partition.

Host_h_redirected
staticmethod

_h_redirected(target, ctl)

Host_h_direct
method

_h_direct(self, ctl)

Hosth_accept
method

h_accept(self, invp)

Allocate a sequence of controllers and process them using h_route.

Hostterminate
method

terminate(self)

Hostxact_void
method

xact_void(self, final)