libmicrohttpd

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

commit 377e2cbd523323e45ece928aee8b6666f2e46f55
parent 8d6d9be08d49507be48541d29d6cda9a5bc81452
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Fri,  4 Nov 2022 15:50:23 +0300

connection: refuse requests with unsupported Transfer-Encoding

The end of the request body (context) cannot be determined if
Transfer-Encoding is not supported.

Diffstat:
Msrc/microhttpd/connection.c | 25++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -90,6 +90,19 @@ #endif /** + * Response text used when the request has unsupported "Transfer-Enconding:". + */ +#ifdef HAVE_MESSAGES +#define REQUEST_UNSUPPORTED_TR_ENCODING \ + "<html>" \ + "<head><title>Unsupported Transfer-Encoding</title></head>" \ + "<body>The Transfer-Encoding used in request is not supported.</body>" \ + "</html>" +#else +#define REQUEST_UNSUPPORTED_TR_ENCODING "" +#endif + +/** * Response text used when the request (http header) is * malformed. * @@ -3975,10 +3988,16 @@ parse_connection_headers (struct MHD_Connection *connection) &enc, NULL)) { + if (! MHD_str_equal_caseless_ (enc, + "chunked")) + { + transmit_error_response_static (connection, + MHD_HTTP_BAD_REQUEST, + REQUEST_UNSUPPORTED_TR_ENCODING); + return; + } + connection->rq.have_chunked_upload = true; connection->rq.remaining_upload_size = MHD_SIZE_UNKNOWN; - if (MHD_str_equal_caseless_ (enc, - "chunked")) - connection->rq.have_chunked_upload = true; } else {