From 3ae9a80a38e6c31728da2442b71e883ead1398f1 Mon Sep 17 00:00:00 2001 From: iduquegit Date: Mon, 20 Jan 2025 10:21:59 +0100 Subject: [PATCH] Update PsychicFileResponse.cpp Set status and content type before chunked response --- src/PsychicFileResponse.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PsychicFileResponse.cpp b/src/PsychicFileResponse.cpp index 656a173..ef4813c 100644 --- a/src/PsychicFileResponse.cpp +++ b/src/PsychicFileResponse.cpp @@ -1,6 +1,7 @@ #include "PsychicFileResponse.h" #include "PsychicRequest.h" #include "PsychicResponse.h" +#include PsychicFileResponse::PsychicFileResponse(PsychicResponse* response, FS& fs, const String& path, const String& contentType, bool download) : PsychicResponseDelegate(response) { @@ -143,6 +144,16 @@ esp_err_t PsychicFileResponse::send() return ESP_FAIL; } + /* Set status and content type before sending headers */ + char* statusBuffer = (char*)malloc(60); + int code = _response->getCode(); + sprintf(statusBuffer, "%u %s", code, http_status_reason(code)); + httpd_resp_set_status(request(), statusBuffer); + + // set the content type + httpd_resp_set_type(request(), getContentType().c_str()); + + // now the headers sendHeaders(); size_t chunksize; @@ -165,6 +176,9 @@ esp_err_t PsychicFileResponse::send() ESP_LOGD(PH_TAG, "File sending complete"); finishChunking(); } + + // Once sent, free our buffer + free(statusBuffer); } return err;