libmicrohttpd

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

commit 3d0516f447ef3ce5567bbe60e15d4ad4633751cd
parent d89c55afe03d2ea42a187e7b9a85938748f801b7
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  1 Jun 2016 20:02:30 +0000

do not generate Content-Length header for 1xx/204/304 replies, also suppress transmission of message body in these cases

Diffstat:
MChangeLog | 3+++
Msrc/include/microhttpd.h | 2+-
Msrc/microhttpd/connection.c | 20+++++++++++++++-----
3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Wed Jun 1 21:59:34 CEST 2016 + Do not send "Content-Length" header for 1xx/204/304 status codes. -CG + Tue May 17 13:32:21 CEST 2016 Allow clients to determine whether a connection is suspended; introduces MHD_CONNECTION_INFO_CONNECTION_SUSPENDED. -CG/FC 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 0x00094903 +#define MHD_VERSION 0x00094904 /** * MHD-internal return code for "YES". diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -876,9 +876,9 @@ build_header_response (struct MHD_Connection *connection) connection->write_buffer_size = 0; return MHD_YES; } + rc = connection->responseCode & (~MHD_ICY_FLAG); if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state) { - rc = connection->responseCode & (~MHD_ICY_FLAG); reason_phrase = MHD_get_reason_phrase_for (rc); sprintf (code, "%s %u %s\r\n", @@ -988,7 +988,13 @@ build_header_response (struct MHD_Connection *connection) have_content_length = MHD_get_response_header (connection->response, MHD_HTTP_HEADER_CONTENT_LENGTH); + /* MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED and 1xx-status + codes SHOULD NOT have a Content-Length according to spec; + also chunked encoding / unknown length or CONNECT... */ if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && + (MHD_HTTP_NO_CONTENT != rc) && + (MHD_HTTP_NOT_MODIFIED != rc) && + (MHD_HTTP_OK < rc) && (NULL == have_content_length) && ( (NULL == connection->method) || (! MHD_str_equal_caseless_ (connection->method, @@ -3101,11 +3107,15 @@ MHD_queue_response (struct MHD_Connection *connection, MHD_increment_response_rc (response); connection->response = response; connection->responseCode = status_code; - if ( (NULL != connection->method) && - (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) ) + if ( ( (NULL != connection->method) && + (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) ) || + (MHD_HTTP_OK > status_code) || + (MHD_HTTP_NO_CONTENT == status_code) || + (MHD_HTTP_NOT_MODIFIED == status_code) ) { - /* if this is a "HEAD" request, pretend that we - have already sent the full message body */ + /* if this is a "HEAD" request, or a status code for + which a body is not allowed, pretend that we + have already sent the full message body. */ connection->response_write_position = response->total_size; } if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) &&