mirror of
https://github.com/owntracks/recorder.git
synced 2026-02-13 20:49:51 +00:00
Send Content-Length header in json_response
This commit is contained in:
6
http.c
6
http.c
@@ -364,9 +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_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, "%zu", content_length);
|
||||
mg_send_header(conn, "Content-Length", buffer);
|
||||
mg_printf_data(conn, js);
|
||||
free(js);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user