Skip to content

Commit

Permalink
prefix Content-Length by X- to avoid issues with chunked encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmens authored and wollew committed Feb 2, 2022
1 parent cd4a0b5 commit 352f3b9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ static int json_response(struct mg_connection *conn, JsonNode *json)
mg_send_header(conn, "Access-Control-Allow-Origin", "*");

if (json == NULL) {
mg_send_header(conn, "Content-Length", "2");
mg_send_header(conn, "X-Content-Length", "2");
mg_printf_data(conn, "{}");
} else {
if ((js = json_stringify(json, JSON_INDENT)) != NULL) {
size_t content_length = strlen(js);
int length = snprintf(NULL, 0, "%zu", content_length);
char buffer[length + 1];
snprintf(buffer, length + 1, "%zu", content_length);
mg_send_header(conn, "Content-Length", buffer);
mg_send_header(conn, "X-Content-Length", buffer);
mg_printf_data(conn, js);
free(js);
}
Expand Down

0 comments on commit 352f3b9

Please sign in to comment.