HTTPResponse¶
HTTPResponse()
¶
Represents an HTTP response with methods to parse the status line and headers.
version = ''
instance-attribute
¶
The HTTP version, e.g. 'HTTP/1.1'.
status_code = 0
instance-attribute
¶
The HTTP status code, e.g. 200, 404, 500.
reason_phrase = ''
instance-attribute
¶
The HTTP reason phrase, e.g. 'OK', 'Not Found', 'Internal Server Error'.
headers = None
instance-attribute
¶
The HTTP headers as an HTTPHeader object.
parse_status_line(status_line)
¶
Parse the status line of an HTTP response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status_line
|
bytes
|
The status line as bytes, e.g. b"HTTP/1.1 200 OK" |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the status line format is invalid |
parse_headers(raw_headers)
¶
Parse raw HTTP headers from bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_headers
|
bytes
|
Raw headers as bytes |
required |