]> granicus.if.org Git - esp-idf/commitdiff
HTTP Server : Added helper functions for sending HTTP error 408 and 500
authorAnurag Kar <anurag.kar@espressif.com>
Tue, 9 Oct 2018 12:33:41 +0000 (18:03 +0530)
committerAnurag Kar <anurag.kar@espressif.com>
Wed, 17 Oct 2018 12:06:50 +0000 (17:36 +0530)
components/http_server/include/http_server.h
components/http_server/src/httpd_txrx.c

index dec25768dfade0db0ab7deba28b04a6734df0883..6a8e65c794dbd8bf4bc6840ce261f31f1034a188 100644 (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
  *
index ed90cb75da17d7fa112abbe0e2f07b1f42d484c8..1ccebabe4fd9ec39e3dba4f914c1c9c3dbf38d2d 100644 (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;