libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit e29cdc78c1e6cc06430c8a798d735f0ef400ce88
parent ff92a15006d6a937ec05dc070c3cc9bb3217703f
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Fri,  3 Jul 2026 20:16:38 +0200

Simplified code introduced by a098c2d3a391381a506f0055b5909bc5e50aaeb2

No more forgotten unlocks

Diffstat:
Msrc/mhd2/response_add_header.c | 42+++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/mhd2/response_add_header.c b/src/mhd2/response_add_header.c @@ -260,6 +260,23 @@ response_add_header_int (struct MHD_Response *restrict response, (NULL != memchr (value, '\r', value_len))) return MHD_SC_RESP_HEADER_VALUE_INVALID; + if (mhd_str_equal_caseless (MHD_HTTP_HEADER_DATE, + name)) + { + if (response->cfg.has_hdr_date) + return MHD_SC_RESP_HEADER_DATE_DUPLICATE; + response->cfg.has_hdr_date = true; + } + if (mhd_str_equal_caseless (MHD_HTTP_HEADER_CONNECTION, + name)) + { + if (response->cfg.has_hdr_conn) + return MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE; + response->cfg.has_hdr_conn = true; + } + + // TODO: add special processing for "Content-Length", "Transfer-Encoding" + if (! response_add_header_no_check (response, name_len, name, value_len, value)) return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; @@ -293,31 +310,6 @@ MHD_response_add_header (struct MHD_Response *MHD_RESTRICT response, else need_unlock = false; - if (mhd_str_equal_caseless (MHD_HTTP_HEADER_DATE, - name)) - { - if (response->cfg.has_hdr_date) - { - if (need_unlock) - mhd_mutex_unlock_chk (&(response->reuse.settings_lock)); - return MHD_SC_RESP_HEADER_DATE_DUPLICATE; - } - response->cfg.has_hdr_date = true; - } - if (mhd_str_equal_caseless (MHD_HTTP_HEADER_CONNECTION, - name)) - { - if (response->cfg.has_hdr_conn) - { - if (need_unlock) - mhd_mutex_unlock_chk (&(response->reuse.settings_lock)); - return MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE; - } - response->cfg.has_hdr_conn = true; - } - - // TODO: add special processing for "Content-Length", "Transfer-Encoding" - res = response_add_header_int (response, name, value); if (need_unlock)