diff options
Diffstat (limited to 'minion/src/wifi_module.cpp')
-rw-r--r-- | minion/src/wifi_module.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp index d377bd8..6c989f9 100644 --- a/minion/src/wifi_module.cpp +++ b/minion/src/wifi_module.cpp @@ -332,13 +332,23 @@ auto WiFiModule::close_connection(NetworkConnection &connection) noexcept -> boo auto WiFiModule::send_response( const NetworkConnection &connection, size_t status_code, - const char *data + const char **headers, + size_t headers_cnt, + const char *body ) noexcept -> bool { const auto *cmd = "AT+CIPSEND"; + auto tot_headers_lengths = 0U; + + for (size_t index = 0U; index < headers_cnt; index++) + { + tot_headers_lengths += strlen(headers[index]) + 2U; + } + const auto data_length = strlen(RESPONSE_HTTP_VERSION) + 1 + - RESPONSE_STATUS_CODE_LENGTH + 4 + strlen(data); + RESPONSE_STATUS_CODE_LENGTH + 4 + strlen(body) + + tot_headers_lengths; auto command_length = SEND_RESPONSE_COMMAND_BASE_LENGTH + strlen(cmd) + data_length; @@ -363,8 +373,17 @@ auto WiFiModule::send_response( _serial.print(RESPONSE_HTTP_VERSION); _serial.print(" "); _serial.print(status_code); - _serial.print("\r\n\r\n"); - _serial.print(data); + _serial.print("\r\n"); + + // Print headers + for (size_t index = 0U; index < headers_cnt; index++) + { + _serial.print(headers[index]); + _serial.print("\r\n"); + } + + _serial.print("\r\n"); + _serial.print(body); strcpy(response, ""); |