aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index d4f25242..e4873073 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -863,6 +863,8 @@ keepalive_possible (struct MHD_Connection *connection)
863{ 863{
864 const char *end; 864 const char *end;
865 865
866 if (MHD_CONN_MUST_CLOSE == connection->keepalive)
867 return MHD_NO;
866 if (NULL == connection->version) 868 if (NULL == connection->version)
867 return MHD_NO; 869 return MHD_NO;
868 if ( (NULL != connection->response) && 870 if ( (NULL != connection->response) &&
@@ -1103,6 +1105,9 @@ build_header_response (struct MHD_Connection *connection)
1103 "close")) ) 1105 "close")) )
1104 client_requested_close = NULL; 1106 client_requested_close = NULL;
1105 1107
1108 if (0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY))
1109 connection->keepalive = MHD_CONN_MUST_CLOSE;
1110
1106 /* now analyze chunked encoding situation */ 1111 /* now analyze chunked encoding situation */
1107 connection->have_chunked_upload = false; 1112 connection->have_chunked_upload = false;
1108 1113
@@ -1148,7 +1153,8 @@ build_header_response (struct MHD_Connection *connection)
1148 1153
1149 /* check for other reasons to add 'close' header */ 1154 /* check for other reasons to add 'close' header */
1150 if ( ( (NULL != client_requested_close) || 1155 if ( ( (NULL != client_requested_close) ||
1151 (connection->read_closed) ) && 1156 (connection->read_closed) ||
1157 (MHD_CONN_MUST_CLOSE == connection->keepalive)) &&
1152 (NULL == response_has_close) && 1158 (NULL == response_has_close) &&
1153 (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) ) 1159 (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) )
1154 must_add_close = MHD_YES; 1160 must_add_close = MHD_YES;
@@ -1196,7 +1202,7 @@ build_header_response (struct MHD_Connection *connection)
1196 if ( (NULL == response_has_keepalive) && 1202 if ( (NULL == response_has_keepalive) &&
1197 (NULL == response_has_close) && 1203 (NULL == response_has_close) &&
1198 (MHD_NO == must_add_close) && 1204 (MHD_NO == must_add_close) &&
1199 (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) && 1205 (MHD_CONN_MUST_CLOSE != connection->keepalive) &&
1200 (MHD_YES == keepalive_possible (connection)) ) 1206 (MHD_YES == keepalive_possible (connection)) )
1201 must_add_keep_alive = MHD_YES; 1207 must_add_keep_alive = MHD_YES;
1202 break; 1208 break;
@@ -1207,6 +1213,14 @@ build_header_response (struct MHD_Connection *connection)
1207 EXTRA_CHECK (0); 1213 EXTRA_CHECK (0);
1208 } 1214 }
1209 1215
1216 if (MHD_CONN_MUST_CLOSE != connection->keepalive)
1217 {
1218 if ( (must_add_close) || (NULL != response_has_close) )
1219 connection->keepalive = MHD_CONN_MUST_CLOSE;
1220 else if ( (must_add_keep_alive) || (NULL != response_has_keepalive) )
1221 connection->keepalive = MHD_CONN_USE_KEEPALIVE;
1222 }
1223
1210 if (must_add_close) 1224 if (must_add_close)
1211 size += MHD_STATICSTR_LEN_ ("Connection: close\r\n"); 1225 size += MHD_STATICSTR_LEN_ ("Connection: close\r\n");
1212 if (must_add_keep_alive) 1226 if (must_add_keep_alive)
@@ -1353,6 +1367,8 @@ transmit_error_response (struct MHD_Connection *connection,
1353 response); 1367 response);
1354 EXTRA_CHECK (NULL != connection->response); 1368 EXTRA_CHECK (NULL != connection->response);
1355 MHD_destroy_response (response); 1369 MHD_destroy_response (response);
1370 /* Do not reuse this connection. */
1371 connection->keepalive = MHD_CONN_MUST_CLOSE;
1356 if (MHD_NO == build_header_response (connection)) 1372 if (MHD_NO == build_header_response (connection))
1357 { 1373 {
1358 /* oops - close! */ 1374 /* oops - close! */
@@ -2799,10 +2815,8 @@ int
2799MHD_connection_handle_idle (struct MHD_Connection *connection) 2815MHD_connection_handle_idle (struct MHD_Connection *connection)
2800{ 2816{
2801 struct MHD_Daemon *daemon = connection->daemon; 2817 struct MHD_Daemon *daemon = connection->daemon;
2802 const char *end;
2803 char *line; 2818 char *line;
2804 size_t line_len; 2819 size_t line_len;
2805 int client_close;
2806 int ret; 2820 int ret;
2807 2821
2808 connection->in_idle = true; 2822 connection->in_idle = true;
@@ -3184,12 +3198,6 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
3184 else 3198 else
3185 socket_start_normal_buffering (connection); 3199 socket_start_normal_buffering (connection);
3186 3200
3187 end =
3188 MHD_get_response_header (connection->response,
3189 MHD_HTTP_HEADER_CONNECTION);
3190 client_close = ( (NULL != end) &&
3191 (MHD_str_equal_caseless_(end,
3192 "close")));
3193 MHD_destroy_response (connection->response); 3201 MHD_destroy_response (connection->response);
3194 connection->response = NULL; 3202 connection->response = NULL;
3195 if ( (NULL != daemon->notify_completed) && 3203 if ( (NULL != daemon->notify_completed) &&
@@ -3201,22 +3209,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
3201 &connection->client_context, 3209 &connection->client_context,
3202 MHD_REQUEST_TERMINATED_COMPLETED_OK); 3210 MHD_REQUEST_TERMINATED_COMPLETED_OK);
3203 } 3211 }
3204 end = 3212 if ( (MHD_CONN_USE_KEEPALIVE != connection->keepalive) ||
3205 MHD_lookup_connection_value (connection, 3213 (connection->read_closed) )
3206 MHD_HEADER_KIND,
3207 MHD_HTTP_HEADER_CONNECTION);
3208 if ( (connection->read_closed) ||
3209 (client_close) ||
3210 ( (NULL != end) &&
3211 (MHD_str_equal_caseless_ (end,
3212 "close")) ) )
3213 {
3214 connection->read_closed = true;
3215 connection->read_buffer_offset = 0;
3216 }
3217 if ( ( (connection->read_closed) &&
3218 (0 == connection->read_buffer_offset) ) ||
3219 (MHD_NO == keepalive_possible (connection) ) )
3220 { 3214 {
3221 /* have to close for some reason */ 3215 /* have to close for some reason */
3222 MHD_connection_close_ (connection, 3216 MHD_connection_close_ (connection,
@@ -3237,6 +3231,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
3237 connection->last = NULL; 3231 connection->last = NULL;
3238 connection->colon = NULL; 3232 connection->colon = NULL;
3239 connection->header_size = 0; 3233 connection->header_size = 0;
3234 connection->keepalive = MHD_CONN_KEEPALIVE_UNKOWN;
3240 /* Reset the read buffer to the starting size, 3235 /* Reset the read buffer to the starting size,
3241 preserving the bytes we have already read. */ 3236 preserving the bytes we have already read. */
3242 connection->read_buffer 3237 connection->read_buffer