libmicrohttpd

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

commit 51da5739fef39eadaadac9a35b94819ee820fd86
parent bc0dcd4cbbb1940df72df4df0649f4023202ed68
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 13 May 2014 16:26:49 +0000

-fix #3397

Diffstat:
MChangeLog | 5+++++
Msrc/include/microhttpd.h | 2+-
Msrc/microhttpd/connection.c | 19++++++++++++++-----
Msrc/microhttpd/internal.h | 2+-
4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Tue May 13 18:24:37 CEST 2014 + Fix accidental transmission of footer termination '\r\n' + for responses with zero byte payload and non-chunked + encoding (#3397). Thanks to amatus for reporting. -CG + Sun May 4 11:05:26 CEST 2014 Fix gnutls header check to make it cross-compile aware. -BK diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -130,7 +130,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00093500 +#define MHD_VERSION 0x00093501 /** * MHD-internal return code for "YES". diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -585,15 +585,23 @@ add_extra_headers (struct MHD_Connection *connection) (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)) ) { - connection->have_chunked_upload = MHD_YES; have_encoding = MHD_get_response_header (connection->response, MHD_HTTP_HEADER_TRANSFER_ENCODING); if (NULL == have_encoding) + { MHD_add_response_header (connection->response, MHD_HTTP_HEADER_TRANSFER_ENCODING, "chunked"); + connection->have_chunked_upload = MHD_YES; + } else if (0 != strcasecmp (have_encoding, "chunked")) + { add_close = MHD_YES; /* application already set some strange encoding, can't do 'chunked' */ + } + else + { + connection->have_chunked_upload = MHD_YES; + } } else { @@ -615,7 +623,7 @@ add_extra_headers (struct MHD_Connection *connection) ( (NULL == connection->method) || (0 != strcasecmp (connection->method, MHD_HTTP_METHOD_CONNECT)) || - (0 != connection->response->total_size) ) ) + (MHD_SIZE_UNKNOWN != connection->response->total_size) ) ) { /* Here we add a content-length if one is missing; however, @@ -2133,7 +2141,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) break; case MHD_CONNECTION_CHUNKED_BODY_READY: do_write (connection); - if (connection->state != MHD_CONNECTION_CHUNKED_BODY_READY) + if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) break; check_write_done (connection, (connection->response->total_size == @@ -2503,8 +2511,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) break; case MHD_CONNECTION_BODY_SENT: build_header_response (connection); - if (connection->write_buffer_send_offset == - connection->write_buffer_append_offset) + if ( (MHD_NO == connection->have_chunked_upload) || + (connection->write_buffer_send_offset == + connection->write_buffer_append_offset) ) connection->state = MHD_CONNECTION_FOOTERS_SENT; else connection->state = MHD_CONNECTION_FOOTERS_SENDING; diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -290,7 +290,7 @@ struct MHD_Response MHD_mutex_ mutex; /** - * Set to MHD_SIZE_UNKNOWN if size is not known. + * Set to #MHD_SIZE_UNKNOWN if size is not known. */ uint64_t total_size;