Merge branch 'bugfix/send_conn_close_header' into 'master'

file_serving example: Demonstrate use of connection close header from request headers

Closes IDFGH-3874

See merge request espressif/esp-idf!11922
pull/6416/head
Mahavir Jain 2021-01-13 22:59:26 +08:00
commit 9ca00064bd
2 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -21,4 +21,10 @@ menu "Http_File_Serving Example menu"
If this config item is set, SDMMC is used to mount the SDcard.
Otherwise, will use SPI host to access and mount the SDcard.
config EXAMPLE_HTTPD_CONN_CLOSE_HEADER
bool "Send connection close header from request handlers"
default y
help
If this config item is set, Connection: close header will be set in handlers.
This closes HTTP connection and frees the server socket instantly.
endmenu

Wyświetl plik

@ -277,6 +277,9 @@ static esp_err_t download_get_handler(httpd_req_t *req)
ESP_LOGI(TAG, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
#ifdef CONFIG_EXAMPLE_HTTPD_CONN_CLOSE_HEADER
httpd_resp_set_hdr(req, "Connection", "close");
#endif
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
@ -388,6 +391,9 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", "/");
#ifdef CONFIG_EXAMPLE_HTTPD_CONN_CLOSE_HEADER
httpd_resp_set_hdr(req, "Connection", "close");
#endif
httpd_resp_sendstr(req, "File uploaded successfully");
return ESP_OK;
}
@ -429,6 +435,9 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
/* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", "/");
#ifdef CONFIG_EXAMPLE_HTTPD_CONN_CLOSE_HEADER
httpd_resp_set_hdr(req, "Connection", "close");
#endif
httpd_resp_sendstr(req, "File deleted successfully");
return ESP_OK;
}