aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-03-07 21:08:53 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-03-07 21:29:41 +0300
commit406c434c722668687d7d752c8d2b6054d4340f3d (patch)
treea60d7806f0bc85c8a91a06e2fe1cbea90e258c14 /src/microhttpd/connection.c
parentedf32d5108765ee98006ad73f652a72e9194487f (diff)
downloadlibmicrohttpd-406c434c722668687d7d752c8d2b6054d4340f3d.tar.gz
libmicrohttpd-406c434c722668687d7d752c8d2b6054d4340f3d.zip
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 (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index f408d1f1..88b1f21d 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2175,6 +2175,7 @@ build_header_response (struct MHD_Connection *connection)
2175 if (c->rp_props.use_reply_body_headers) 2175 if (c->rp_props.use_reply_body_headers)
2176 { 2176 {
2177 /* Body-specific headers */ 2177 /* Body-specific headers */
2178
2178 if (c->rp_props.chunked) 2179 if (c->rp_props.chunked)
2179 { /* Chunked encoding is used */ 2180 { /* Chunked encoding is used */
2180 if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED)) 2181 if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))
@@ -2185,23 +2186,26 @@ build_header_response (struct MHD_Connection *connection)
2185 return MHD_NO; 2186 return MHD_NO;
2186 } 2187 }
2187 } 2188 }
2188 else 2189 else /* Chunked encoding is not used */
2189 { /* Chunked encoding is not used */ 2190 {
2190 if (MHD_SIZE_UNKNOWN != r->total_size) 2191 if (MHD_SIZE_UNKNOWN != r->total_size)
2191 { 2192 { /* The size is known */
2192 if (! buffer_append_s (buf, &pos, buf_size, 2193 if (0 == (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH))
2193 MHD_HTTP_HEADER_CONTENT_LENGTH ": ")) 2194 { /* The response does not have "Content-Length" header */
2194 return MHD_NO; 2195 if (! buffer_append_s (buf, &pos, buf_size,
2195 el_size = MHD_uint64_to_str (r->total_size, buf + pos, 2196 MHD_HTTP_HEADER_CONTENT_LENGTH ": "))
2196 buf_size - pos); 2197 return MHD_NO;
2197 if (0 == el_size) 2198 el_size = MHD_uint64_to_str (r->total_size, buf + pos,
2198 return MHD_NO; 2199 buf_size - pos);
2199 pos += el_size; 2200 if (0 == el_size)
2200 2201 return MHD_NO;
2201 if (buf_size < pos + 2) 2202 pos += el_size;
2202 return MHD_NO; 2203
2203 buf[pos++] = '\r'; 2204 if (buf_size < pos + 2)
2204 buf[pos++] = '\n'; 2205 return MHD_NO;
2206 buf[pos++] = '\r';
2207 buf[pos++] = '\n';
2208 }
2205 } 2209 }
2206 } 2210 }
2207 } 2211 }