futurefinity.protocol – HTTP Protocol Implementation

class futurefinity.protocol.BaseHTTPConnectionController(*args, **kwargs)[source]

FutureFinity Base HTTP Connection Controller Class.

This is the model controller to the HTTP Connections.

Any Connection Controllers should based on this class.

cancel_timeout_handler()[source]

Cancel the EventLoop.call_later instance, prevent transport be closed accidently.

error_received(incoming, exc: tuple)[source]

Triggered when errors received when errors occurred during parsing the message.

initial_received(incoming: futurefinity.protocol.HTTPIncomingMessage)[source]

Triggered when the initial of a message is received.

message_received(incoming: futurefinity.protocol.HTTPIncomingMessage)[source]

Triggered when a message is completely received.

This will not be triggered when the message is detected as a stream message.

set_timeout_handler(suggested_time: typing.Union=None)[source]

Set a EventLoop.call_later instance, close transport after timeout.

stream_received(incoming: futurefinity.protocol.HTTPIncomingMessage, data: bytes)[source]

Triggered when the stream of a message is received.

This will only be triggered when the message is detected as a stream message.

class futurefinity.protocol.CapitalizedHTTPv1Headers(*args, **kwargs)[source]

Convert a string to HTTPHeader style capitalize.

>>> capitalize_header = CapitalizedHTTPv1Header()
>>> capitalize_header["set-cookie"]
'Set-Cookie'
>>> capitalize_header["SET-COOKIE"]
'Set-Cookie'
>>> capitalize_header["sET-CooKIe"]
'Set-Cookie'
>>> capitalize_header["MY-cUsToM-heAdER"]
'My-Custom-Header'
exception futurefinity.protocol.ConnectionBadMessage[source]

FutureFinity Connection Bad Message Error.

This Error is raised when the message is not a valid message.

exception futurefinity.protocol.ConnectionEntityTooLarge[source]

FutureFinity Connection Entity Too Large Error.

This Error is raised when the message too large that FutureFinity cannot handle.

exception futurefinity.protocol.ConnectionParseError[source]

FutureFinity Connection Parse Error.

Any Connection Parse Errors is based on this class.

class futurefinity.protocol.HTTPHeaders(*args, **kwargs)[source]

HTTPHeaders class, based on TolerantMagicDict.

It has not only all the features from TolerantMagicDict, but also can parse and make HTTP Headers.

accept_cookies_for_request(cookies: http.cookies.SimpleCookie)[source]

Insert all the cookies as a request cookie header.

accept_cookies_for_response(cookies: http.cookies.SimpleCookie)[source]

Insert all the cookies as response set cookie headers.

assemble() → bytes[source]

Assemble a HTTPHeaders Class to HTTP/1.x Form.

load_headers(data: typing.Union)[source]

Load HTTP Headers from another object.

It will raise an Error if the header is invalid.

class futurefinity.protocol.HTTPIncomingMessage[source]

FutureFinity HTTP Incoming Message Class.

This is the base class of HTTPIncomingRequest and HTTPIncomingResponse.

scheme

Return the scheme that the connection used.

class futurefinity.protocol.HTTPIncomingRequest(method: str, origin_path: str, headers: futurefinity.protocol.HTTPHeaders, connection: 'HTTPv1Connection', http_version: int=10, body: typing.Union=None)[source]

FutureFinity HTTP Incoming Request Class.

This is a subclass of the HTTPIncomingMessage.

This class represents a Incoming HTTP Request.

body_args

Parse body arguments and return body arguments in a proper instance.

cookies

Parse cookies and return cookies in a HTTPCookies instance.

host

Parse host and return the host in str.

Parse link arguments and return link arguments in a TolerantMagicDict instance.

path

Parse path and return the path in str.

class futurefinity.protocol.HTTPIncomingResponse(status_code: int, http_version: int=10, headers: futurefinity.protocol.HTTPHeaders=None, body: typing.Union=None, connection: 'HTTPv1Connection'=None)[source]

FutureFinity HTTP Incoming Response Class.

This is a subclass of the HTTPIncomingMessage.

This class represents a Incoming HTTP Response.

cookies

Parse cookies and return cookies in a HTTPCookies instance.

class futurefinity.protocol.HTTPMultipartBody(*args, **kwargs)[source]

HTTPBody class, based on TolerantMagicDict.

It has not only all the features from TolerantMagicDict, but also can parse and make HTTP Body.

assemble() → typing.Tuple[source]

Generate HTTP v1 Body to bytes.

It will return the body in bytes and the content-type in str.

static parse(content_type: str, data: bytes) → 'HTTPMultipartBody'[source]

Parse HTTP v1 Multipart Body.

It will raise an Error during the parse period if parse failed.

class futurefinity.protocol.HTTPMultipartFileField(fieldname: str, filename: str, content: bytes, content_type: str='application/octet-stream', headers: typing.Union=None, encoding: str='binary')[source]

Containing a file as a http form field.

assemble() → bytes[source]

Convert this form field to bytes.

class futurefinity.protocol.HTTPv1Connection(controller: futurefinity.protocol.BaseHTTPConnectionController, is_client: bool, http_version: int=10, use_tls: bool=False, sockname: typing.Union=None, peername: typing.Union=None, allow_keep_alive: bool=True)[source]

FutureFinity HTTP v1 Connection Class.

This class will control and parse the http v1 connection.

connection_lost(exc: typing.Union=None)[source]

Triggered when remote is closed.

data_received(data: bytes)[source]

Trigger this function when data is received from the remote.

finish_writing()[source]

Trigger this function when everything is written.

It will reset the connection or close it.

write_body(body: bytes)[source]

Write the body to remote.

This can be triggered for many times. until finish_writing is triggered.

write_initial(http_version: typing.Union=None, method: str='GET', path: str='/', status_code: int=200, headers: typing.Union=None)[source]

Write the initial to remote.

exception futurefinity.protocol.ProtocolError[source]

FutureFinity Protocol Error.

All Errors from the Protocol are based on this class.