commit aa69e178d21cb3dcfd8bd11e56cc6dc6ae39adb6
parent f46f4b75dd3bc97f3e20403fde46d37087f89d61
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Sun, 6 Mar 2022 21:11:26 +0300
response: added automatic flag MHD_RAF_HAS_CONTENT_LENGTH
Diffstat:
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
@@ -327,8 +327,9 @@ enum MHD_ResponseAutoFlags
MHD_RAF_NO_FLAGS = 0, /**< No auto flags */
MHD_RAF_HAS_CONNECTION_HDR = 1 << 0, /**< Has "Connection" header */
MHD_RAF_HAS_CONNECTION_CLOSE = 1 << 1, /**< Has "Connection: close" */
- MHD_RAF_HAS_TRANS_ENC_CHUNKED = 1 << 2, /**< Has "Transfer-Encoding: chunked */
- MHD_RAF_HAS_DATE_HDR = 1 << 3 /**< Has "Date" header */
+ MHD_RAF_HAS_TRANS_ENC_CHUNKED = 1 << 2, /**< Has "Transfer-Encoding: chunked" */
+ MHD_RAF_HAS_CONTENT_LENGTH = 1 << 3, /**< Has "Content-Length" header */
+ MHD_RAF_HAS_DATE_HDR = 1 << 4 /**< Has "Date" header */
} _MHD_FIXED_FLAGS_ENUM;
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
@@ -541,13 +541,24 @@ MHD_add_response_header (struct MHD_Response *response,
}
return MHD_NO;
}
- if ( (0 == (MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
- & response->flags)) &&
- (MHD_str_equal_caseless_ (header,
- MHD_HTTP_HEADER_CONTENT_LENGTH)) )
+
+ if (MHD_str_equal_caseless_ (header,
+ MHD_HTTP_HEADER_CONTENT_LENGTH))
{
- /* MHD will set Content-length if allowed and possible,
- reject attempt by application */
+ if (0 == (MHD_RF_INSANITY_HEADER_CONTENT_LENGTH & response->flags))
+ {
+ /* MHD sets automatically correct Content-Length always when needed,
+ reject attempt to manually override it */
+ return MHD_NO;
+ }
+ if (MHD_NO != add_response_entry (response,
+ MHD_HEADER_KIND,
+ header,
+ content))
+ {
+ response->flags_auto |= MHD_RAF_HAS_CONTENT_LENGTH;
+ return MHD_YES;
+ }
return MHD_NO;
}
@@ -644,6 +655,19 @@ MHD_del_response_header (struct MHD_Response *response,
header_len) )
response->flags_auto &=
~((enum MHD_ResponseAutoFlags) MHD_RAF_HAS_DATE_HDR);
+ else if ( (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_LENGTH) ==
+ header_len) &&
+ MHD_str_equal_caseless_bin_n_ (header,
+ MHD_HTTP_HEADER_CONTENT_LENGTH,
+ header_len) )
+ {
+ if (NULL == MHD_get_response_element_n_ (response,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_CONTENT_LENGTH,
+ header_len))
+ response->flags_auto &=
+ ~((enum MHD_ResponseAutoFlags) MHD_RAF_HAS_CONTENT_LENGTH);
+ }
return MHD_YES;
}
pos = pos->next;