aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-01 17:52:48 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-01 17:52:48 +0000
commit4eb568c37c922b829bf81173006761b0adc1f4db (patch)
treecd2ad3ad5943421dc0165e5c834967e396c4e7c5
parentfcf8127533ad1cef4447ef420cf722b85347e227 (diff)
downloadlibmicrohttpd-4eb568c37c922b829bf81173006761b0adc1f4db.tar.gz
libmicrohttpd-4eb568c37c922b829bf81173006761b0adc1f4db.zip
send connection:close always if we shutdown socket for reading, see mantis #1760
-rw-r--r--ChangeLog5
-rw-r--r--src/daemon/connection.c26
2 files changed, 28 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 6018d463..8014353b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
1Tue Nov 1 18:51:50 CET 2011
2 Force adding of 'Connection: close' to the header if we (for whatever
3 reason) are shutting down the socket for reading (see also
4 #1760). -CG
5
1Thu Oct 27 14:16:34 CEST 2011 6Thu Oct 27 14:16:34 CEST 2011
2 Treat EAGAIN the same way as EINTR (helps on W32). -LRN 7 Treat EAGAIN the same way as EINTR (helps on W32). -LRN
3 8
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index c75c0aee..a7f3ceae 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -608,10 +608,10 @@ try_grow_read_buffer (struct MHD_Connection *connection)
608 return MHD_YES; 608 return MHD_YES;
609} 609}
610 610
611
611/** 612/**
612 * Allocate the connection's write buffer and 613 * Allocate the connection's write buffer and fill it with all of the
613 * fill it with all of the headers (or footers, 614 * headers (or footers, if we have already sent the body) from the
614 * if we have already sent the body) from the
615 * HTTPd's response. 615 * HTTPd's response.
616 */ 616 */
617static int 617static int
@@ -626,6 +626,7 @@ build_header_response (struct MHD_Connection *connection)
626 enum MHD_ValueKind kind; 626 enum MHD_ValueKind kind;
627 const char *reason_phrase; 627 const char *reason_phrase;
628 uint32_t rc; 628 uint32_t rc;
629 int must_add_close;
629 630
630 EXTRA_CHECK (NULL != connection->version); 631 EXTRA_CHECK (NULL != connection->version);
631 if (0 == strlen(connection->version)) 632 if (0 == strlen(connection->version))
@@ -669,6 +670,13 @@ build_header_response (struct MHD_Connection *connection)
669 kind = MHD_FOOTER_KIND; 670 kind = MHD_FOOTER_KIND;
670 off = 0; 671 off = 0;
671 } 672 }
673 must_add_close = ( (connection->read_closed == MHD_YES) &&
674 (0 == strcasecmp (connection->version,
675 MHD_HTTP_VERSION_1_1)) &&
676 (NULL == MHD_get_response_header (connection->response,
677 MHD_HTTP_HEADER_CONNECTION)) );
678 if (must_add_close)
679 size += strlen ("Connection: close\r\n");
672 pos = connection->response->first_header; 680 pos = connection->response->first_header;
673 while (pos != NULL) 681 while (pos != NULL)
674 { 682 {
@@ -689,6 +697,16 @@ build_header_response (struct MHD_Connection *connection)
689 { 697 {
690 memcpy (data, code, off); 698 memcpy (data, code, off);
691 } 699 }
700 if (must_add_close)
701 {
702 /* we must add the 'close' header because circumstances forced us to
703 stop reading from the socket; however, we are not adding the header
704 to the response as the response may be used in a different context
705 as well */
706 memcpy (&data[off], "Connection: close\r\n",
707 strlen ("Connection: close\r\n"));
708 off += strlen ("Connection: close\r\n");
709 }
692 pos = connection->response->first_header; 710 pos = connection->response->first_header;
693 while (pos != NULL) 711 while (pos != NULL)
694 { 712 {
@@ -703,6 +721,7 @@ build_header_response (struct MHD_Connection *connection)
703 } 721 }
704 memcpy (&data[off], "\r\n", 2); 722 memcpy (&data[off], "\r\n", 2);
705 off += 2; 723 off += 2;
724
706 if (off != size) 725 if (off != size)
707 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); 726 mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
708 connection->write_buffer = data; 727 connection->write_buffer = data;
@@ -712,6 +731,7 @@ build_header_response (struct MHD_Connection *connection)
712 return MHD_YES; 731 return MHD_YES;
713} 732}
714 733
734
715/** 735/**
716 * We encountered an error processing the request. 736 * We encountered an error processing the request.
717 * Handle it properly by stopping to read data 737 * Handle it properly by stopping to read data