HTTPTask#
top.web.task.HTTPTask class.
- class HTTPTask[source]#
Bases:
TaskA task for tracking HTTP requests.
- __init__(task_id=None, task_name=None, host_name=None, process_id=None, thread_id=None, process_internal_id=None, processor_name=None, started_at=None, updated_at=None, ended_at=None, recorded_successfully=None, tags=None, command_line=None, protocol=None, host=None, method=None, path=None, params=None, uri=None, client_ip_address=None, request_headers=None, status_code=None, status_message=None, response_headers=None)#
- Parameters:
- Return type:
None
Methods
__init__([task_id, task_name, host_name, ...])create_from_current_thread(task_id[, ...])Create a task and assuming the processor is the current OS thread.
deserialise(blob)Serialise using dataclasses_json
from_dict(kvs, *[, infer_missing])from_json(s, *[, parse_float, parse_int, ...])HTTP request header shortcut method.
get_ago()Get how long ago this task finished.
Get the content length of the response.
get_duration()Get the duration of this task.
get_flag()Return the Unicode flag emoticon based on the country IP address.
get_host()HTTP request header shortcut method.
Return the country code of the client IP address.
Get the originating IP address of the requestor.
get_processor_tracking_id()Get the key used in our tracking table (Redis) for this task.
Get a value of a single HTTP header in a request.
Get a value of a single HTTP header in a response.
HTTP request header shortcut method.
schema(*[, infer_missing, only, exclude, ...])serialise()Serialise using dataclasS_json
to_dict([encode_json])to_json(*[, skipkeys, ensure_ascii, ...])Attributes
IP address that connected to the web server.
command_lineApplication command line
ended_atWhen this task was ended.
Host from incoming HTTP request
host_nameHost name on multiserver deployments.
HTTP method like GET, POST, put
HTTP GET request params
Request path, like /api/my-func
process_idOS process id that started this task.
process_internal_idIf the application provides further ids for the processes.
processor_nameHuman readable of the processor name is available
Protocol from incoming HTTP request
recorded_successfullyDid this task success?
Request HTTP headers.
Response HTTP headers.
started_atWhen this task was started.
When response has been generated, what code did we sent.
Server status message
tagsGeneric tracking tags that can be associated with tasks.
task_idUnique identified for this task.
task_namemethodandpath.thread_idOS thread that started this task.
updated_atWhen this task was last updated.
The full request URI if available
- client_ip_address: Optional[str] = None#
IP address that connected to the web server.
This is the direct IP address of the TCP/IP connection. You probably want
get_original_ip()in most of the cases.
- request_headers: Optional[List[Tuple[str, str]]] = None#
Request HTTP headers.
Available as key value mapping.
Note that in HTTP protocol a header can appear twice.
Uppercase all key names.
- status_code: Optional[int] = None#
When response has been generated, what code did we sent. Only available when the request processing has finished.
- response_headers: Optional[List[Tuple[str, str]]] = None#
Response HTTP headers.
Available as key value mapping.
Note that in HTTP protocol a header can appear twice. Uppercase all key names.
- get_single_request_header(name)[source]#
Get a value of a single HTTP header in a request.
- Parameters:
name (str) – Case insensitive HTTP header name
- Raises:
AssertionError – If the same header appears twice
- Returns:
The header value
- Return type:
- get_single_response_header(name)[source]#
Get a value of a single HTTP header in a response.
- Parameters:
name (str) – Case insensitive HTTP header name
- Raises:
AssertionError – If the same header appears twice
- Returns:
The header value
- Return type:
- get_ip_country()[source]#
Return the country code of the client IP address.
Currently only supports cf-ipcountry header.
- Returns:
ISO 3166-1 Alpha 2 country code of the client as uppercase. Special codes like T1 are returned for Tor network, etc.
- Return type:
- get_flag()[source]#
Return the Unicode flag emoticon based on the country IP address.
See
get_ip_country()- Return type:
- get_original_ip()[source]#
Get the originating IP address of the requestor.
In the case the HTTP request was forwarded through services like Cloudflare and reverse proxies like Nginx and Apache, get the user IP address.
- Return type:
- __init__(task_id=None, task_name=None, host_name=None, process_id=None, thread_id=None, process_internal_id=None, processor_name=None, started_at=None, updated_at=None, ended_at=None, recorded_successfully=None, tags=None, command_line=None, protocol=None, host=None, method=None, path=None, params=None, uri=None, client_ip_address=None, request_headers=None, status_code=None, status_message=None, response_headers=None)#
- Parameters:
- Return type:
None