Espressif ESP32-S2 Programming Manual page 587

Table of Contents

Advertisement

Chapter 2. API Reference
• ESP_ERR_INVALID_ARG : Null arguments
Parameters
• [in] hd: HTTPD instance handle
• [in] sockfd: Session socket FD
• [in] pending_func: The receive function to be set for this session
int
httpd_req_to_sockfd(httpd_req_t
Get the Socket Descriptor from the HTTP request.
This API will return the socket descriptor of the session for which URI handler was executed on reception of
HTTP request. This is useful when user wants to call functions that require session socket fd, from within a
URI handler, ie. : httpd_sess_get_ctx(), httpd_sess_trigger_close(), httpd_sess_update_lru_counter().
Note This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid.
Return
• Socket descriptor : The socket descriptor for this request
• -1 : Invalid/NULL request pointer
Parameters
• [in] r: The request whose socket descriptor should be found
int
httpd_req_recv(httpd_req_t
API to read content data from the HTTP request.
This API will read HTTP content data from the HTTP request into provided buffer. Use content_len provided
in httpd_req_t structure to know the length of data to be fetched. If content_len is too large for the buffer then
user may have to make multiple calls to this function, each time fetching 'buf_len'number of bytes, while
the pointer to content data is incremented internally by the same number.
Note
• This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid.
• If an error is returned, the URI handler must further return an error. This will ensure that the
erroneous socket is closed and cleaned up by the web server.
• Presently Chunked Encoding is not supported
Return
• Bytes : Number of bytes read into the buffer successfully
• 0 : Buffer length parameter is zero / connection closed by peer
• HTTPD_SOCK_ERR_INVALID : Invalid arguments
• HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
• HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
Parameters
• [in] r: The request being responded to
• [in] buf: Pointer to a buffer that the data will be read into
• [in] buf_len: Length of the buffer
size_t
httpd_req_get_hdr_value_len(httpd_req_t
Search for a field in request headers and return the string length of it's value.
Note
• This API is supposed to be called only from the context of a URI handler where httpd_req_t* request
pointer is valid.
• Once httpd_resp_send() API is called all request headers are purged, so request headers need be
copied into separate buffers if they are required later.
Return
• Length : If field is found in the request URL
• Zero : Field not found / Invalid request / Null arguments
Parameters
• [in] r: The request being responded to
• [in] field: The header field to be searched in the request
esp_err_t httpd_req_get_hdr_value_str(httpd_req_t
Espressif Systems
*r)
*r, char *buf, size_t buf_len)
*r, const char *field)
val_size)
576
Submit Document Feedback
*r, const char *field, char *val, size_t
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF