From b57b7d1a3d079bad116219027cad82b4f00b787f Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 3 Sep 2026 22:18:45 +0200 Subject: [PATCH] httpd: answer /cmd with the shared text header The /cmd path carried its own copy of the plain-text response header, which was the same string page_impl.c already keeps in HTTP_RESPONCE_TXT, minus one difference: the shared one never said Connection: close. This httpd closes after every response, so a reply that does not advertise it invites the browser to reuse the socket and lose the next request. HTTP_RESPONCE_JSON has always said so; the text one was the odd one out, and send_config() and send_cmd_log() were answering without it. The copy is gone and the shared string carries the header. The check for a command that printed nothing now compares against the length strtox() returned instead of sizeof() on the macro. --- httpd/httpd.c | 11 ++++------- httpd/page_impl.c | 2 +- httpd/page_impl.h | 2 ++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/httpd/httpd.c b/httpd/httpd.c index 50de43ed..c5f514ad 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -16,11 +16,6 @@ #define CMARK_S 6 -/* Answer to POST /cmd. Kept as a macro so that its length is known at compile - * time: an unchanged slen afterwards means the command printed nothing. */ -#define CMD_RESPONSE_HEADER "HTTP/1.1 200 OK\r\nConnection: close\r\n" \ - "Content-Type: text/plain\r\n\r\n" - #pragma codeseg BANK1 #pragma constseg BANK1 @@ -631,7 +626,9 @@ static void handle_firmware_fragment(__xdata uint8_t *p) static void run_cmd_body(__xdata uint8_t *body) { - slen = strtox(outbuf, CMD_RESPONSE_HEADER); + uint16_t hdr_len = strtox(outbuf, HTTP_RESPONCE_TXT); + + slen = hdr_len; cmd_capture = 1; execute_commands(body); if (cmd_capture == 2) @@ -640,7 +637,7 @@ static void run_cmd_body(__xdata uint8_t *body) /* Commands that configure something print nothing at all. Saying * so beats an empty body, which reads the same as "nothing ran". * Only on success: a silent failure must not answer with "OK". */ - if (err_status == ERR_OK && slen == sizeof(CMD_RESPONSE_HEADER) - 1) + if (err_status == ERR_OK && slen == hdr_len) slen += strtox(outbuf + slen, "OK\n"); /* On a parse error keep what the parser printed, because that text * is the explanation, and only restate the status. "400 NO" is as diff --git a/httpd/page_impl.c b/httpd/page_impl.c index d063f4c1..a3ecd649 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -48,7 +48,7 @@ extern __xdata char sfp_module_serial[2][17]; extern __xdata uint8_t sfp_options[2]; __code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n"; -__code uint8_t * __code HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n"; +__code uint8_t * __code HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n"; // Convert uint8_t to ascii HEX char push on html-buffer. void charhex_to_html(char c) diff --git a/httpd/page_impl.h b/httpd/page_impl.h index 31a6e08d..cad4cd6f 100644 --- a/httpd/page_impl.h +++ b/httpd/page_impl.h @@ -3,6 +3,8 @@ #include +extern __code uint8_t * __code HTTP_RESPONCE_TXT; + bool send_counters(uint8_t phys_port); void send_status(void); void send_vlan(uint16_t vlan);