Module httoolsp.headers
Submodule for headers manipulation
Functions
| parse_header(header) | Parse a header into a main value and a table of parameters. |
| parse_accept_header(header, strict) | Parse accept header and return instance of AcceptHeader. |
Class AcceptHeader
| AcceptHeader\get_weight(media_type) | Get weight of passed media type. |
| AcceptHeader\negotiate(media_types) | Get "best" media type and its weight. |
Functions
- parse_header(header)
-
Parse a header into a main value and a table of parameters.
This function is partially based on
cgi.parse_headerfrom CPython.Parameters:
- header string
Returns:
- string main value
- table table of parameters
- parse_accept_header(header, strict)
-
Parse
acceptheader and return instance of AcceptHeader.Parameters:
- header string
- strict
optional bool
enable strict mode. Default is
false.
Returns:
-
table
AcceptHeader instance
Or
- nil
- string error message
Class AcceptHeader
A class representing parsed
accept header.
Cannot be instantiated directly, use parse_accept_header.
- AcceptHeader\get_weight(media_type)
-
Get weight of passed media type.
Returns
nilif media type is not accepted.Parameters:
- media_type string media type
Returns:
-
float
weight
Or
-
nil
- AcceptHeader\negotiate(media_types)
-
Get "best" media type and its weight.
Returns
nilif no media type is accepted.Parameters:
- media_types table array of media types
Returns:
- string media type
- float weight
Or
-
nil