@@ -408,6 +408,8 @@ static esp_err_t cb_headers_complete(http_parser *parser)
408408
409409 parser_data -> status = PARSING_BODY ;
410410 ra -> remaining_len = r -> content_len ;
411+ struct httpd_data * hd = (struct httpd_data * ) r -> handle ;
412+ hd -> http_server_state = HTTP_SERVER_EVENT_ON_HEADER ;
411413 esp_http_server_dispatch_event (HTTP_SERVER_EVENT_ON_HEADER , & (ra -> sd -> fd ), sizeof (int ));
412414 return ESP_OK ;
413415}
@@ -1209,3 +1211,44 @@ esp_err_t httpd_req_get_cookie_val(httpd_req_t *req, const char *cookie_name, ch
12091211 return ret ;
12101212
12111213}
1214+
1215+ /* Get the length of the raw request data received from the client.
1216+ */
1217+ size_t httpd_get_raw_req_data_len (httpd_req_t * req )
1218+ {
1219+ if (req == NULL ) {
1220+ return 0 ;
1221+ }
1222+ struct httpd_req_aux * ra = req -> aux ;
1223+ return ra -> scratch_cur_size ;
1224+ }
1225+
1226+ /* Get the raw request data, which contains the raw HTTP request headers and
1227+ * URI related information. Internally, the httpd_parse.c file uses a scratch buffer
1228+ * to store the original HTTP request data exactly as received from the client.
1229+ * This function returns the contents of this scratch buffer.
1230+ *
1231+ * NOTE - This function returns different data for different http server states.
1232+ * 1. HTTP_SERVER_EVENT_ON_CONNECTED - Returns the data containing information related to URI and headers.
1233+ * 2. HTTP_SERVER_EVENT_ON_HEADER - Returns the data containing information related to only headers.
1234+ * 3. HTTP_SERVER_EVENT_ON_DATA - Returns the data containing information related to only headers.
1235+ * 4. HTTP_SERVER_EVENT_SENT_DATA - Returns the data containing information related to only headers.
1236+ * 5. HTTP_SERVER_EVENT_DISCONNECTED - Returns the data containing information related to only headers.
1237+ * 6. HTTP_SERVER_EVENT_STOP - Returns the data containing information related to only headers.
1238+ */
1239+ esp_err_t httpd_get_raw_req_data (httpd_req_t * req , char * buf , size_t buf_len )
1240+ {
1241+ if (req == NULL || buf == NULL ) {
1242+ return ESP_ERR_INVALID_ARG ;
1243+ }
1244+ if (buf_len == 0 ) {
1245+ return ESP_ERR_INVALID_ARG ;
1246+ }
1247+ if (req -> aux == NULL ) {
1248+ ESP_LOGW (TAG , "Request auxiliary data is NULL for URI: [%s]" , req -> uri ? req -> uri : "(null)" );
1249+ return ESP_ERR_INVALID_ARG ;
1250+ }
1251+ struct httpd_req_aux * ra = req -> aux ;
1252+ memcpy (buf , ra -> scratch , buf_len );
1253+ return ESP_OK ;
1254+ }
0 commit comments