commit 406c434c722668687d7d752c8d2b6054d4340f3d
parent edf32d5108765ee98006ad73f652a72e9194487f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Mon, 7 Mar 2022 21:08:53 +0300
response headers: do not add automatic "Content-Length" header if response already has it
If application used MHD_RF_INSANITY_HEADER_CONTENT_LENGTH response flag
and added manual "Content-Length" header, MHD will not add the correct
header.
Diffstat:
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -2175,6 +2175,7 @@ build_header_response (struct MHD_Connection *connection)
if (c->rp_props.use_reply_body_headers)
{
/* Body-specific headers */
+
if (c->rp_props.chunked)
{ /* Chunked encoding is used */
if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))
@@ -2185,23 +2186,26 @@ build_header_response (struct MHD_Connection *connection)
return MHD_NO;
}
}
- else
- { /* Chunked encoding is not used */
+ else /* Chunked encoding is not used */
+ {
if (MHD_SIZE_UNKNOWN != r->total_size)
- {
- if (! buffer_append_s (buf, &pos, buf_size,
- MHD_HTTP_HEADER_CONTENT_LENGTH ": "))
- return MHD_NO;
- el_size = MHD_uint64_to_str (r->total_size, buf + pos,
- buf_size - pos);
- if (0 == el_size)
- return MHD_NO;
- pos += el_size;
-
- if (buf_size < pos + 2)
- return MHD_NO;
- buf[pos++] = '\r';
- buf[pos++] = '\n';
+ { /* The size is known */
+ if (0 == (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH))
+ { /* The response does not have "Content-Length" header */
+ if (! buffer_append_s (buf, &pos, buf_size,
+ MHD_HTTP_HEADER_CONTENT_LENGTH ": "))
+ return MHD_NO;
+ el_size = MHD_uint64_to_str (r->total_size, buf + pos,
+ buf_size - pos);
+ if (0 == el_size)
+ return MHD_NO;
+ pos += el_size;
+
+ if (buf_size < pos + 2)
+ return MHD_NO;
+ buf[pos++] = '\r';
+ buf[pos++] = '\n';
+ }
}
}
}