diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-01 20:02:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-01 20:02:30 +0000 |
commit | 3d0516f447ef3ce5567bbe60e15d4ad4633751cd (patch) | |
tree | 638e4545973e2fbf835196995384271391494e12 /src/microhttpd/connection.c | |
parent | d89c55afe03d2ea42a187e7b9a85938748f801b7 (diff) | |
download | libmicrohttpd-3d0516f447ef3ce5567bbe60e15d4ad4633751cd.tar.gz libmicrohttpd-3d0516f447ef3ce5567bbe60e15d4ad4633751cd.zip |
do not generate Content-Length header for 1xx/204/304 replies, also suppress transmission of message body in these cases
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 882e23ca..257ce6c4 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -876,9 +876,9 @@ build_header_response (struct MHD_Connection *connection) | |||
876 | connection->write_buffer_size = 0; | 876 | connection->write_buffer_size = 0; |
877 | return MHD_YES; | 877 | return MHD_YES; |
878 | } | 878 | } |
879 | rc = connection->responseCode & (~MHD_ICY_FLAG); | ||
879 | if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state) | 880 | if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state) |
880 | { | 881 | { |
881 | rc = connection->responseCode & (~MHD_ICY_FLAG); | ||
882 | reason_phrase = MHD_get_reason_phrase_for (rc); | 882 | reason_phrase = MHD_get_reason_phrase_for (rc); |
883 | sprintf (code, | 883 | sprintf (code, |
884 | "%s %u %s\r\n", | 884 | "%s %u %s\r\n", |
@@ -988,7 +988,13 @@ build_header_response (struct MHD_Connection *connection) | |||
988 | have_content_length = MHD_get_response_header (connection->response, | 988 | have_content_length = MHD_get_response_header (connection->response, |
989 | MHD_HTTP_HEADER_CONTENT_LENGTH); | 989 | MHD_HTTP_HEADER_CONTENT_LENGTH); |
990 | 990 | ||
991 | /* MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED and 1xx-status | ||
992 | codes SHOULD NOT have a Content-Length according to spec; | ||
993 | also chunked encoding / unknown length or CONNECT... */ | ||
991 | if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && | 994 | if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && |
995 | (MHD_HTTP_NO_CONTENT != rc) && | ||
996 | (MHD_HTTP_NOT_MODIFIED != rc) && | ||
997 | (MHD_HTTP_OK < rc) && | ||
992 | (NULL == have_content_length) && | 998 | (NULL == have_content_length) && |
993 | ( (NULL == connection->method) || | 999 | ( (NULL == connection->method) || |
994 | (! MHD_str_equal_caseless_ (connection->method, | 1000 | (! MHD_str_equal_caseless_ (connection->method, |
@@ -3101,11 +3107,15 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
3101 | MHD_increment_response_rc (response); | 3107 | MHD_increment_response_rc (response); |
3102 | connection->response = response; | 3108 | connection->response = response; |
3103 | connection->responseCode = status_code; | 3109 | connection->responseCode = status_code; |
3104 | if ( (NULL != connection->method) && | 3110 | if ( ( (NULL != connection->method) && |
3105 | (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) ) | 3111 | (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) ) || |
3112 | (MHD_HTTP_OK > status_code) || | ||
3113 | (MHD_HTTP_NO_CONTENT == status_code) || | ||
3114 | (MHD_HTTP_NOT_MODIFIED == status_code) ) | ||
3106 | { | 3115 | { |
3107 | /* if this is a "HEAD" request, pretend that we | 3116 | /* if this is a "HEAD" request, or a status code for |
3108 | have already sent the full message body */ | 3117 | which a body is not allowed, pretend that we |
3118 | have already sent the full message body. */ | ||
3109 | connection->response_write_position = response->total_size; | 3119 | connection->response_write_position = response->total_size; |
3110 | } | 3120 | } |
3111 | if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) && | 3121 | if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) && |