commit efdaa50c6c681358c22594bac28a5b1b87967b03
parent 027d34ceec0282c1c3a4e737bc34dcaabfa5bdb6
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 23 Nov 2026 18:28:42 +0100
get_req_header(): reordered branches
Diffstat:
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -6442,25 +6442,16 @@ get_req_header (struct MHD_Connection *c,
if ( (! c->rq.hdrs.hdr.name_end_found) &&
(! c->rq.hdrs.hdr.starts_with_ws) )
{
- /* Processing the header (field) name */
- if ( (! allow_extended_charset) &&
- (':' != chr) &&
- (! char_legal_in_field_name (chr)) )
- {
- transmit_error_response_static (c,
- MHD_HTTP_BAD_REQUEST,
- ERR_RSP_INVALID_CHAR_IN_FIELD_NAME);
- return MHD_HDR_LINE_READING_DATA_ERROR;
- }
+ /* Processing the header (field) string before the header value */
- if (':' == chr)
+ if (':' != chr)
{
- if (0 == c->rq.hdrs.hdr.ws_start)
- c->rq.hdrs.hdr.name_len = p;
- else
+ /* Processing the header (field) name */
+ if (0 != c->rq.hdrs.hdr.ws_start)
{
+ /* End of the whitespace in header (field) name */
mhd_assert (allow_wsp_in_name || allow_wsp_before_colon);
- if (! allow_wsp_before_colon)
+ if (! allow_wsp_in_name)
{
if (! process_footers)
transmit_error_response_static (c,
@@ -6470,35 +6461,31 @@ get_req_header (struct MHD_Connection *c,
transmit_error_response_static (c,
MHD_HTTP_BAD_REQUEST,
ERR_RSP_WSP_IN_FOOTER_NAME);
+
return MHD_HDR_LINE_READING_DATA_ERROR; /* Error in the request */
}
- c->rq.hdrs.hdr.name_len = c->rq.hdrs.hdr.ws_start;
#ifndef MHD_FAVOR_SMALL_CODE
c->rq.hdrs.hdr.ws_start = 0; /* Not on whitespace anymore */
#endif /* ! MHD_FAVOR_SMALL_CODE */
}
- if ((0 == c->rq.hdrs.hdr.name_len) && ! allow_empty_name)
+ if ( (! allow_extended_charset) &&
+ (! char_legal_in_field_name (chr)) )
{
- if (! process_footers)
- transmit_error_response_static (c,
- MHD_HTTP_BAD_REQUEST,
- ERR_RSP_EMPTY_HEADER_NAME);
- else
- transmit_error_response_static (c,
- MHD_HTTP_BAD_REQUEST,
- ERR_RSP_EMPTY_FOOTER_NAME);
- return MHD_HDR_LINE_READING_DATA_ERROR; /* Error in the request */
+ transmit_error_response_static (c,
+ MHD_HTTP_BAD_REQUEST,
+ ERR_RSP_INVALID_CHAR_IN_FIELD_NAME);
+ return MHD_HDR_LINE_READING_DATA_ERROR;
}
- c->rq.hdrs.hdr.name_end_found = true;
- c->read_buffer[c->rq.hdrs.hdr.name_len] = 0; /* Zero-terminate the name */
+
}
else
{
- if (0 != c->rq.hdrs.hdr.ws_start)
+ if (0 == c->rq.hdrs.hdr.ws_start)
+ c->rq.hdrs.hdr.name_len = p;
+ else
{
- /* End of the whitespace in header (field) name */
mhd_assert (allow_wsp_in_name || allow_wsp_before_colon);
- if (! allow_wsp_in_name)
+ if (! allow_wsp_before_colon)
{
if (! process_footers)
transmit_error_response_static (c,
@@ -6508,13 +6495,27 @@ get_req_header (struct MHD_Connection *c,
transmit_error_response_static (c,
MHD_HTTP_BAD_REQUEST,
ERR_RSP_WSP_IN_FOOTER_NAME);
-
return MHD_HDR_LINE_READING_DATA_ERROR; /* Error in the request */
}
+ c->rq.hdrs.hdr.name_len = c->rq.hdrs.hdr.ws_start;
#ifndef MHD_FAVOR_SMALL_CODE
c->rq.hdrs.hdr.ws_start = 0; /* Not on whitespace anymore */
#endif /* ! MHD_FAVOR_SMALL_CODE */
}
+ if ((0 == c->rq.hdrs.hdr.name_len) && ! allow_empty_name)
+ {
+ if (! process_footers)
+ transmit_error_response_static (c,
+ MHD_HTTP_BAD_REQUEST,
+ ERR_RSP_EMPTY_HEADER_NAME);
+ else
+ transmit_error_response_static (c,
+ MHD_HTTP_BAD_REQUEST,
+ ERR_RSP_EMPTY_FOOTER_NAME);
+ return MHD_HDR_LINE_READING_DATA_ERROR; /* Error in the request */
+ }
+ c->rq.hdrs.hdr.name_end_found = true;
+ c->read_buffer[c->rq.hdrs.hdr.name_len] = 0; /* Zero-terminate the name */
}
}
else