Implicit bindings for HTTP incoming- and outgoing data for a server.
More...
|
int | http_strand_id () |
| The identity of the current asynchronous strand serving the request.
|
|
http_in_t * | http_req () |
| Return the current HTTP request.
|
|
http_out_t * | http_resp () |
| Return the current HTTP response.
|
|
void | http_resp_add_header (const char *name, const char *value) |
| Add a header to the current HTTP response. More...
|
|
bool | http_resp_status_sent () |
| Return true if the HTTP response status was sent.
|
|
void | http_resp_send_status (http_status_t status) |
| Send the headers and the response status without a body. More...
|
|
nodec_stream_t * | http_resp_send_status_body (http_status_t status, size_t content_length, const char *content_type) |
| Send the headers and response status, and return a reponse body stream. More...
|
|
void | http_resp_send_ok () |
| Send the headers and OK response without a body. More...
|
|
void | http_resp_send_body_buf (http_status_t status, uv_buf_t buf, const char *content_type) |
| Send headers, status, and full body as a buffer.
|
|
void | http_resp_send_body_str (http_status_t status, const char *body, const char *content_type) |
| Send headers, status, and full body as a string.
|
|
const char * | http_req_url () |
| Return the current request url.
|
|
const nodec_url_t * | http_req_parsed_url () |
| Return the parsed full request url, including the path, hash, query etc.
|
|
const char * | http_req_path () |
| Return the current request path.
|
|
http_method_t | http_req_method () |
| Return the current request method.
|
|
uint64_t | http_req_content_length () |
| The value of the Content-Length header. More...
|
|
const char * | http_req_header (const char *name) |
| Return the value of an HTTP request header. More...
|
|
const char * | http_req_header_next (const char **value, size_t *iter) |
| Iterate through all headers. More...
|
|
nodec_bstream_t * | http_req_body () |
| Return the current HTTP request body as a buffered stream. More...
|
|
uv_buf_t | async_req_read_body (size_t read_max) |
| Read the full HTTP request body. More...
|
|
const char * | async_req_read_body_str (size_t read_max) |
| Read the full body as a string. More...
|
|
void | http_req_print () |
| Print a request for debugging purposes.
|
|
Implicit bindings for HTTP incoming- and outgoing data for a server.
The HTTP(S) server implicitly binds the current request and response objects (as dynamically bound implicit parameters). They can be accessed through http_req_xxx
for requests and http_resp_xxx
for responses.
◆ async_req_read_body()
uv_buf_t async_req_read_body |
( |
size_t |
read_max | ) |
|
Read the full HTTP request body.
The returned buffer should be deallocated by the caller.
- Parameters
-
read_max | maximum bytes to read (or 0 for unlimited reading) |
- Returns
- the buffer with the full request body. Handles
chunked
request bodies, and does automatic decompression if the request body had a Content-Encoding of gzip
.
◆ async_req_read_body_str()
const char* async_req_read_body_str |
( |
size_t |
read_max | ) |
|
Read the full body as a string.
Only works if the body cannot contain 0 characters. The returned string should be deallocated by the caller.
- Parameters
-
read_max | maximum bytes to read (or 0 for unlimited reading) |
- Returns
- the buffer with the full request body. Handles
chunked
request bodies, and does automatic decompression if the request body had a Content-Encoding of gzip
.
◆ http_req_body()
Return the current HTTP request body as a buffered stream.
Handles chunked bodies, and does automatic decompression if the Content-Encoding
was gzip
.
◆ http_req_content_length()
uint64_t http_req_content_length |
( |
| ) |
|
The value of the Content-Length header.
- Returns
- 0 if the Content-Length header was not present.
◆ http_req_header()
const char* http_req_header |
( |
const char * |
name | ) |
|
Return the value of an HTTP request header.
- Parameters
-
- Returns
- the header value (owned by the request object) or NULL if the header was not present. If there were multiple headers the values are joined with commas into one value. See http_header_next_field() for iterating through them.
◆ http_req_header_next()
const char* http_req_header_next |
( |
const char ** |
value, |
|
|
size_t * |
iter |
|
) |
| |
Iterate through all headers.
- Parameters
-
[out] | value | the value of the current header, or NULL if done iterating. |
[in,out] | iter | the iteration state, should be initialized to 0. |
- Returns
- the name of the current header or NULL if done iterating.
◆ http_resp_add_header()
void http_resp_add_header |
( |
const char * |
name, |
|
|
const char * |
value |
|
) |
| |
Add a header to the current HTTP response.
- Parameters
-
name | the name of the header |
value | the value of the header the name and value are copied into the header block and can be freed afterwards. |
◆ http_resp_send_ok()
void http_resp_send_ok |
( |
| ) |
|
Send the headers and OK response without a body.
Just a shorthand for http_resp_send_status(HTTP_STATUS_OK).
◆ http_resp_send_status()
Send the headers and the response status without a body.
- Parameters
-
status | The HTTP response status. |
◆ http_resp_send_status_body()
Send the headers and response status, and return a reponse body stream.
- Parameters
-
status | The HTTP response status |
content_length | The length of the response body. Use NODEC_CHUNKED for a chunked transfer encoding where the content length is unknown ahead of time. |
content_type | The mime content type (like text/html ). The charset can be specified too (like text/html;charset=UTF-8 ) but is otherwise determined automatically from the mime type. if the content_type is NULL no Content-Type header is added. |
- Returns
- A stream to write the body to; this is automatically chunked if NODEC_CHUNKED was passed as the
content_length
.