libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit a60173864e4e50fab7676653cfce04421828cef3
parent bbbcf4838ae137052e8b8a98f26e14a90c8b420c
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 13 Jun 2021 17:23:19 +0300

MHD_queue_response(): refuse 1xx codes in HTTP/1.0 mode

See https://datatracker.ietf.org/doc/html/rfc7231#section-6.2

Diffstat:
Msrc/microhttpd/connection.c | 39+++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -4247,12 +4247,6 @@ MHD_queue_response (struct MHD_Connection *connection, { struct MHD_Daemon *daemon; - if ( (NULL == connection) || - (NULL == response) || - (NULL != connection->response) || - ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) && - (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) ) - return MHD_NO; daemon = connection->daemon; if (daemon->shutdown) @@ -4271,6 +4265,14 @@ MHD_queue_response (struct MHD_Connection *connection, return MHD_NO; } #endif + + if ( (NULL == connection) || + (NULL == response) || + (NULL != connection->response) || + ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) && + (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) ) + return MHD_NO; + #ifdef UPGRADE_SUPPORT if ( (NULL != response->upgrade_handler) && (0 == (daemon->options & MHD_ALLOW_UPGRADE)) ) @@ -4304,6 +4306,31 @@ MHD_queue_response (struct MHD_Connection *connection, #endif return MHD_NO; } + if (200 > (status_code & (~MHD_ICY_FLAG))) + { + if (MHD_HTTP_VER_1_0 == connection->http_ver) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _ ("Wrong status code (%u) refused. " \ + "HTTP/1.0 clients do not support 1xx status codes!\n"), + (status_code & (~MHD_ICY_FLAG))); +#endif + return MHD_NO; + } + if (0 != response->flags & (MHD_RF_HTTP_VERSION_1_0_ONLY + | MHD_RF_HTTP_VERSION_1_0_RESPONSE)) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _ ("Wrong status code (%u) refused. " \ + "HTTP/1.0 reply mode does not support 1xx status codes!\n"), + (status_code & (~MHD_ICY_FLAG))); +#endif + return MHD_NO; + } + } + MHD_increment_response_rc (response); connection->response = response; connection->responseCode = status_code;