HTTP¶
The rite.net.http submodule contains utilities related to HTTP status codes, methods, and header parsing.
HTTP Module¶
HTTP protocol utilities.
This submodule provides utilities for HTTP status codes, methods, and header parsing.
Examples¶
from rite.net.http import ( ... http_status_code, ... http_is_method ... ) http_status_code(200) 'OK'
Modules¶
http_is_method
¶
HTTP Methods¶
Check if HTTP method is valid.
Examples¶
from rite.net.http import http_is_method http_is_method("GET") True
http_parse_headers
¶
HTTP Headers Parser¶
Parse HTTP headers from string.
Examples¶
from rite.net.http import http_parse_headers headers = "Content-Type: application/json\r\nHost: example.com" http_parse_headers(headers)
Functions¶
http_parse_headers(headers_str: str) -> dict[str, str]
¶
Parse HTTP headers from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers_str
|
str
|
Raw headers string. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of header name to value. |
Examples:
>>> http_parse_headers("User-Agent: Mozilla/5.0")
{'User-Agent': 'Mozilla/5.0'}
>>> http_parse_headers(
... "Accept: text/html\r\nAccept-Encoding: gzip"
... )
{'Accept': 'text/html', 'Accept-Encoding': 'gzip'}
Notes
Splits on colon (:). Handles \r\n line endings.
http_status_code
¶
HTTP Status Codes¶
HTTP status code constants and utilities.
Examples¶
from rite.net.http import http_status_code http_status_code(200) 'OK'
Functions¶
http_status_code(code: int) -> str
¶
Get HTTP status description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
int
|
HTTP status code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Status description. |
Examples:
>>> http_status_code(200)
'OK'
>>> http_status_code(404)
'Not Found'
>>> http_status_code(500)
'Internal Server Error'
Notes
Uses http.HTTPStatus from standard library.
options: show_root_heading: true show_source: false heading_level: 2