Chapter 2. API Reference
Note User specified recv function must handle errors internally, depending upon the set value of errno,
and return specific HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as return value
of httpd_req_recv() function
Return
• Bytes : The number of bytes received 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] hd: server instance
• [in] sockfd: session socket file descriptor
• [in] buf: buffer with bytes to send
• [in] buf_len: data size
• [in] flags: flags for the send() function
typedef int (*httpd_pending_func_t)(httpd_handle_t hd, int sockfd)
Prototype for HTTPDs low-level “get pending bytes”function.
Note User specified pending function must handle errors internally, depending upon the set value of errno,
and return specific HTTPD_SOCK_ERR_ codes, which will be handled accordingly in the server task.
Return
• Bytes : The number of bytes waiting to be received
• HTTPD_SOCK_ERR_INVALID : Invalid arguments
• HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket pending()
• HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket pending()
Parameters
• [in] hd: server instance
• [in] sockfd: session socket file descriptor
typedef esp_err_t (*httpd_err_handler_func_t)(httpd_req_t *req, httpd_err_code_t error)
Function prototype for HTTP error handling.
This function is executed upon HTTP errors generated during internal processing of an HTTP request. This is
used to override the default behavior on error, which is to send HTTP error response and close the underlying
socket.
Note
• If implemented, the server will not automatically send out HTTP error response codes, therefore,
httpd_resp_send_err() must be invoked inside this function if user wishes to generate HTTP error
responses.
• When invoked, the validity of uri, method, content_len and user_ctx fields of the
httpd_req_t parameter is not guaranteed as the HTTP request may be partially received/parsed.
• The function must return ESP_OK if underlying socket needs to be kept open. Any other
value will ensure that the socket is closed. The return value is ignored when error is of type
HTTPD_500_INTERNAL_SERVER_ERROR and the socket closed anyway.
Return
• ESP_OK : error handled successful
• ESP_FAIL : failure indicates that the underlying socket needs to be closed
Parameters
• [in] req: HTTP request for which the error needs to be handled
• [in] error: Error type
typedef void *httpd_handle_t
HTTP Server Instance Handle.
Every instance of the server will have a unique handle.
typedef enum http_method httpd_method_t
HTTP Method Type wrapper over “enum http_method”available in “http_parser”library.
typedef void (*httpd_free_ctx_fn_t)(void *ctx)
Prototype for freeing context data (if any)
Espressif Systems 591
Submit Document Feedback
Release v4.4