HTTPRequest¶
HTTPRequest
¶
Represents an HTTP request with methods to parse the request line and headers.
host
instance-attribute
¶
The target host of the HTTP request.
port
instance-attribute
¶
The target port of the HTTP request.
scheme
instance-attribute
¶
The scheme of the HTTP request, either 'http' or 'https'.
version
instance-attribute
¶
The HTTP version, e.g. 'HTTP/1.1'.
method
instance-attribute
¶
The HTTP method, e.g. 'GET', 'POST', 'CONNECT'.
path
instance-attribute
¶
The path of the HTTP request, e.g. '/'.
headers
instance-attribute
¶
The HTTP headers as an HTTPHeader object.
parse_request_line(request_line)
¶
Parse the request line of an HTTP request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_line
|
bytes
|
The request line as bytes, e.g. b"GET / HTTP/1.1" |
required |
parse_headers(raw_headers)
¶
Parse raw HTTP headers from bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_headers
|
bytes
|
Raw headers as bytes |
required |
parse_host()
¶
Parse the Host header to set the host and port attributes.
url()
¶
Construct the full URL of the HTTP request.
Returns:
| Type | Description |
|---|---|
str
|
The full URL as a string |