summaryrefslogtreecommitdiff
path: root/minion/src/wifi_module.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-23 15:27:49 +0200
committerHampusM <hampus@hampusmat.com>2022-05-23 15:27:49 +0200
commitfb4ffea4161c3ac88eeb43bc886fab63dfdc3891 (patch)
tree9a268ac6950873f6c80fdec7c95ed52dc5521d09 /minion/src/wifi_module.cpp
parent0ef43baf0fc5db3a069047ac4f06bf20227f63b5 (diff)
feat(minion): add response headers
Diffstat (limited to 'minion/src/wifi_module.cpp')
-rw-r--r--minion/src/wifi_module.cpp27
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, "");