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

Closes: https://github.com/espressif/esp-idf/issues/5775
This commit is contained in:
Shubham Kulkarni
2021-01-08 11:48:52 +05:30
committed by bot
parent 09604d6519
commit 6f91d408ab
2 changed files with 15 additions and 0 deletions

View File

@@ -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;
}