Mstdlib-1.24.0
|
Functions | |
unsigned char * | M_http_simple_write_request (M_http_method_t method, const char *host, unsigned short port, const char *uri, const char *user_agent, const char *content_type, const M_hash_dict_t *headers, const unsigned char *data, size_t data_len, const char *charset, size_t *len) |
M_bool | M_http_simple_write_request_buf (M_buf_t *buf, M_http_method_t method, const char *host, unsigned short port, const char *uri, const char *user_agent, const char *content_type, const M_hash_dict_t *headers, const unsigned char *data, size_t data_len, const char *charset) |
unsigned char * | M_http_simple_write_response (M_uint32 code, const char *reason, const char *content_type, const M_hash_dict_t *headers, const unsigned char *data, size_t data_len, const char *charset, size_t *len) |
M_bool | M_http_simple_write_response_buf (M_buf_t *buf, M_uint32 code, const char *reason, const char *content_type, const M_hash_dict_t *headers, const unsigned char *data, size_t data_len, const char *charset) |
Generate request and response messages.
Does not support:
unsigned char * M_http_simple_write_request | ( | M_http_method_t | method, |
const char * | host, | ||
unsigned short | port, | ||
const char * | uri, | ||
const char * | user_agent, | ||
const char * | content_type, | ||
const M_hash_dict_t * | headers, | ||
const unsigned char * | data, | ||
size_t | data_len, | ||
const char * | charset, | ||
size_t * | len | ||
) |
Create an HTTP/1.1 request message, return as a new string.
Caller is responsible for freeing the returned string.
If the Content-Length header is not provided in headers, it will be added automatically for you, using data_len as the length. Data can be NULL If either the header or data_len is provided. Data can be sent later. This allows generating the header and sending large messages without buffering the data in memory. In this case, this function will generate the necessary HTTP header part of the message.
If set host, port, uri, user_agent, and content_type will all override any that were previoiusly set in the headers.
[in] | method | HTTP verb to use (GET, POST, etc). |
[in] | host | Host the request will be sent to. Required if 'Host' header is not set. |
[in] | port | Port the request will be sent on. 0 or 80 will not set the port part of the 'Host' Header. However, if the port is 0 it is assumed to be 80. Will be ignored if 'Host' header is set. |
[in] | uri | URI (may be absolute or relative, may include query string). Typically, this will be relative. if absolute, the host and port should match the host and port parameters. |
[in] | user_agent | Optional user agent to include in the request. |
[in] | content_type | Optional content type. If not set and not in headers this will default to 'plain/text'. |
[in] | headers | Additional headers to include in request. |
[in] | data | String to place in body of message (may be empty). |
[in] | data_len | Number of chars to use from data (may be 0). Cannot be 0 if data is NULL. |
[in] | charset | Encoding of the data. M_TEXTCODEC_UNKNOWN should be used if charset should not be added to the Content-Type header. This will overwrite the charset if already present in Content-Type. Also use M_TEXTCODEC_UNKNOWN for non-text data. |
[out] | len | Place to store length of returned HTTP request message (may be NULL). |
M_bool M_http_simple_write_request_buf | ( | M_buf_t * | buf, |
M_http_method_t | method, | ||
const char * | host, | ||
unsigned short | port, | ||
const char * | uri, | ||
const char * | user_agent, | ||
const char * | content_type, | ||
const M_hash_dict_t * | headers, | ||
const unsigned char * | data, | ||
size_t | data_len, | ||
const char * | charset | ||
) |
Create an HTTP/1.1 request message, add it to the given buffer.
Same as M_http_simple_write_request(), except that it adds the new message to the given buffer instead of returning it in a newly-allocated string.
[out] | buf | Buffer to add the message to. |
[in] | method | HTTP verb to use (GET, POST, etc). |
[in] | host | Host the request will be sent to. Required if 'Host' header is not set. |
[in] | port | Port the request will be sent on. 0 or 80 will not set the port part of the 'Host' Header. However, if the port is 0 it is assumed to be 80. Will be ignored if 'Host' header is set. |
[in] | uri | URI (may be absolute or relative, may include query string). Typically, this will be relative. if absolute, the host and port should match the host and port parameters. |
[in] | user_agent | Optional user agent to include in the request. |
[in] | content_type | Optional content type. If not set and not in headers this will default to 'plain/text'. |
[in] | headers | Additional headers to include in request. |
[in] | data | String to place in body of message (may be empty). |
[in] | data_len | Number of chars to use from data (may be 0). Cannot be 0 if data is NULL. |
[in] | charset | Encoding of the data. Set NULL or empty to not add a charset to the Content-Type header. If set, this will overwrite the charset if already present in Content-Type. |
unsigned char * M_http_simple_write_response | ( | M_uint32 | code, |
const char * | reason, | ||
const char * | content_type, | ||
const M_hash_dict_t * | headers, | ||
const unsigned char * | data, | ||
size_t | data_len, | ||
const char * | charset, | ||
size_t * | len | ||
) |
Create an HTTP/1.1 response message, return as new string.
Caller is responsible for freeing the returned string.
If the Content-Length header is not provided in headers, it will be added automatically for you, using data_len as the length. Data can be NULL If either the header or data_len is provided. Data can be sent later. This allows generating the header and sending large messages without buffering the data in memory. In this case, this function will generate the necessary HTTP header part of the message.
[in] | code | HTTP status code to use (200, 404, etc). |
[in] | reason | HTTP status reason string. If NULL, will attempt to pick one automatically based on code. |
[in] | content_type | Optional content type. If not set and not in headers this will default to 'plain/text'. |
[in] | headers | Headers to include in response. |
[in] | data | String to place in body of message (may be empty). |
[in] | data_len | Number of chars to use from data (may be 0). |
[in] | charset | Encoding of the data. Set NULL or empty to not add a charset to the Content-Type header. If set, this will overwrite the charset if already present in Content-Type. |
[out] | len | Place to store length of returned HTTP response message (may be NULL). |
M_bool M_http_simple_write_response_buf | ( | M_buf_t * | buf, |
M_uint32 | code, | ||
const char * | reason, | ||
const char * | content_type, | ||
const M_hash_dict_t * | headers, | ||
const unsigned char * | data, | ||
size_t | data_len, | ||
const char * | charset | ||
) |
Create an HTTP/1.1 response message, add it to the given buffer.
Same as M_http_simple_write_response(), except that it adds the new message to the given buffer instead of returning it in a newly-allocated string.
[out] | buf | Buffer to add the message to. |
[in] | code | HTTP status code to use (200, 404, etc). |
[in] | reason | HTTP status reason string. If NULL, will attempt to pick one automatically based on code. |
[in] | content_type | Optional content type. If not set and not in headers this will default to 'plain/text'. |
[in] | headers | Headers to include in response. |
[in] | data | String to place in body of message (may be empty). |
[in] | data_len | Number of chars to use from data (may be 0). |
[in] | charset | Encoding of the data. Set NULL or empty to not add a charset to the Content-Type header. If set, this will overwrite the charset if already present in Content-Type. |