HTTP Server : Added helper functions for sending HTTP error 408 and 500

This commit is contained in:
Anurag Kar 2018-10-09 18:03:41 +05:30
parent 30632c0c34
commit ae5989528e
2 changed files with 57 additions and 0 deletions

View File

@ -687,6 +687,7 @@ esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, size_t buf_len)
#define HTTPD_207 "207 Multi-Status" /*!< HTTP Response 207 */
#define HTTPD_400 "400 Bad Request" /*!< HTTP Response 400 */
#define HTTPD_404 "404 Not Found" /*!< HTTP Response 404 */
#define HTTPD_408 "408 Request Timeout" /*!< HTTP Response 408 */
#define HTTPD_500 "500 Internal Server Error" /*!< HTTP Response 500 */
/**
@ -791,6 +792,52 @@ esp_err_t httpd_resp_set_hdr(httpd_req_t *r, const char *field, const char *valu
*/
esp_err_t httpd_resp_send_404(httpd_req_t *r);
/**
* @brief Helper function for HTTP 408
*
* Send HTTP 408 message. If you wish to send additional data in the body of the
* response, please use the lower-level functions directly.
*
* @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 this API is called, all request headers are purged, so
* request headers need be copied into separate buffers if
* they are required later.
*
* @param[in] r The request being responded to
*
* @return
* - ESP_OK : On successfully sending the response packet
* - ESP_ERR_INVALID_ARG : Null arguments
* - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
*/
esp_err_t httpd_resp_send_408(httpd_req_t *r);
/**
* @brief Helper function for HTTP 500
*
* Send HTTP 500 message. If you wish to send additional data in the body of the
* response, please use the lower-level functions directly.
*
* @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 this API is called, all request headers are purged, so
* request headers need be copied into separate buffers if
* they are required later.
*
* @param[in] r The request being responded to
*
* @return
* - ESP_OK : On successfully sending the response packet
* - ESP_ERR_INVALID_ARG : Null arguments
* - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
*/
esp_err_t httpd_resp_send_500(httpd_req_t *r);
/**
* @brief Raw HTTP send
*

View File

@ -376,6 +376,16 @@ esp_err_t httpd_resp_send_404(httpd_req_t *r)
return httpd_resp_send_err(r, HTTPD_404_NOT_FOUND);
}
esp_err_t httpd_resp_send_408(httpd_req_t *r)
{
return httpd_resp_send_err(r, HTTPD_408_REQ_TIMEOUT);
}
esp_err_t httpd_resp_send_500(httpd_req_t *r)
{
return httpd_resp_send_err(r, HTTPD_500_SERVER_ERROR);
}
esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_resp_t error)
{
const char *msg;