diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 8217932e..39e00dd7 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -66,13 +66,12 @@ | |||
66 | * Add extra debug messages with reasons for closing connections | 66 | * Add extra debug messages with reasons for closing connections |
67 | * (non-error reasons). | 67 | * (non-error reasons). |
68 | */ | 68 | */ |
69 | #define DEBUG_CLOSE 0 | 69 | #define DEBUG_CLOSE MHD_NO |
70 | |||
71 | 70 | ||
72 | /** | 71 | /** |
73 | * Should all data send be printed to stderr? | 72 | * Should all data send be printed to stderr? |
74 | */ | 73 | */ |
75 | #define DEBUG_SEND_DATA 0 | 74 | #define DEBUG_SEND_DATA MHD_NO |
76 | 75 | ||
77 | 76 | ||
78 | /** | 77 | /** |
@@ -604,11 +603,11 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
604 | char *colon; | 603 | char *colon; |
605 | char *tmp; | 604 | char *tmp; |
606 | const char *clen; | 605 | const char *clen; |
607 | const char *end; | ||
608 | unsigned long long cval; | 606 | unsigned long long cval; |
609 | struct MHD_Response *response; | 607 | struct MHD_Response *response; |
610 | 608 | ||
611 | if (connection->bodyReceived == MHD_YES) | 609 | if ( (connection->bodyReceived == MHD_YES) || |
610 | (connection->headersReceived == MHD_YES) ) | ||
612 | abort (); | 611 | abort (); |
613 | colon = NULL; /* make gcc happy */ | 612 | colon = NULL; /* make gcc happy */ |
614 | last = NULL; | 613 | last = NULL; |
@@ -691,17 +690,6 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
691 | connection->bodyReceived = MHD_NO; | 690 | connection->bodyReceived = MHD_NO; |
692 | } | 691 | } |
693 | } | 692 | } |
694 | end = MHD_lookup_connection_value (connection, | ||
695 | MHD_HEADER_KIND, | ||
696 | MHD_HTTP_HEADER_CONNECTION); | ||
697 | if ((end != NULL) && (0 == strcasecmp (end, "close"))) | ||
698 | { | ||
699 | /* other side explicitly requested | ||
700 | that we close the connection after | ||
701 | this request */ | ||
702 | connection->read_close = MHD_YES; | ||
703 | } | ||
704 | |||
705 | if ((0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) | 693 | if ((0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) |
706 | && (NULL != connection->version) | 694 | && (NULL != connection->version) |
707 | && (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) | 695 | && (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) |
@@ -724,7 +712,6 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
724 | MHD_queue_response (connection, MHD_HTTP_BAD_REQUEST, response); | 712 | MHD_queue_response (connection, MHD_HTTP_BAD_REQUEST, response); |
725 | MHD_destroy_response (response); | 713 | MHD_destroy_response (response); |
726 | } | 714 | } |
727 | |||
728 | break; | 715 | break; |
729 | } | 716 | } |
730 | /* line should be normal header line, find colon */ | 717 | /* line should be normal header line, find colon */ |
@@ -808,7 +795,7 @@ MHD_call_connection_handler (struct MHD_Connection *connection) | |||
808 | connection->read_buffer, &processed, | 795 | connection->read_buffer, &processed, |
809 | &connection->client_context)) | 796 | &connection->client_context)) |
810 | { | 797 | { |
811 | /* serios internal error, close connection */ | 798 | /* serious internal error, close connection */ |
812 | #if HAVE_MESSAGES | 799 | #if HAVE_MESSAGES |
813 | MHD_DLOG (connection->daemon, | 800 | MHD_DLOG (connection->daemon, |
814 | "Internal application error, closing connection.\n"); | 801 | "Internal application error, closing connection.\n"); |
@@ -820,8 +807,8 @@ MHD_call_connection_handler (struct MHD_Connection *connection) | |||
820 | memmove (connection->read_buffer, | 807 | memmove (connection->read_buffer, |
821 | &connection->read_buffer[connection->readLoc - processed], | 808 | &connection->read_buffer[connection->readLoc - processed], |
822 | processed); | 809 | processed); |
823 | if (connection->uploadSize != -1) | 810 | if (connection->uploadSize != -1) |
824 | connection->uploadSize -= (connection->readLoc - processed); | 811 | connection->uploadSize -= (connection->readLoc - processed); |
825 | connection->readLoc = processed; | 812 | connection->readLoc = processed; |
826 | if ((connection->uploadSize == 0) || | 813 | if ((connection->uploadSize == 0) || |
827 | ((connection->readLoc == 0) && | 814 | ((connection->readLoc == 0) && |
@@ -921,6 +908,12 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
921 | #endif | 908 | #endif |
922 | #endif | 909 | #endif |
923 | shutdown (connection->socket_fd, SHUT_RD); | 910 | shutdown (connection->socket_fd, SHUT_RD); |
911 | if ( (connection->headersReceived == MHD_NO) || | ||
912 | (connection->bodyReceived == MHD_NO) ) { | ||
913 | /* no request => no response! */ | ||
914 | CLOSE (connection->socket_fd); | ||
915 | connection->socket_fd = -1; | ||
916 | } | ||
924 | return MHD_YES; | 917 | return MHD_YES; |
925 | } | 918 | } |
926 | connection->readLoc += bytes_read; | 919 | connection->readLoc += bytes_read; |
@@ -1059,6 +1052,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1059 | { | 1052 | { |
1060 | struct MHD_Response *response; | 1053 | struct MHD_Response *response; |
1061 | int ret; | 1054 | int ret; |
1055 | const char * end; | ||
1062 | 1056 | ||
1063 | if (MHD_need_100_continue (connection)) | 1057 | if (MHD_need_100_continue (connection)) |
1064 | { | 1058 | { |
@@ -1194,6 +1188,9 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1194 | connection, | 1188 | connection, |
1195 | &connection->client_context, | 1189 | &connection->client_context, |
1196 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | 1190 | MHD_REQUEST_TERMINATED_COMPLETED_OK); |
1191 | end = MHD_lookup_connection_value (connection, | ||
1192 | MHD_HEADER_KIND, | ||
1193 | MHD_HTTP_HEADER_CONNECTION); | ||
1197 | connection->client_context = NULL; | 1194 | connection->client_context = NULL; |
1198 | connection->continuePos = 0; | 1195 | connection->continuePos = 0; |
1199 | connection->responseCode = 0; | 1196 | connection->responseCode = 0; |
@@ -1204,7 +1201,14 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
1204 | connection->bodyReceived = MHD_NO; | 1201 | connection->bodyReceived = MHD_NO; |
1205 | connection->messagePos = 0; | 1202 | connection->messagePos = 0; |
1206 | connection->method = NULL; | 1203 | connection->method = NULL; |
1207 | connection->url = NULL; | 1204 | connection->url = NULL; |
1205 | if ((end != NULL) && (0 == strcasecmp (end, "close"))) | ||
1206 | { | ||
1207 | /* other side explicitly requested | ||
1208 | that we close the connection after | ||
1209 | this request */ | ||
1210 | connection->read_close = MHD_YES; | ||
1211 | } | ||
1208 | if ((connection->read_close == MHD_YES) || | 1212 | if ((connection->read_close == MHD_YES) || |
1209 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) | 1213 | (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) |
1210 | { | 1214 | { |