diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/microhttpd/connection.c | 26 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 10 |
2 files changed, 22 insertions, 14 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 1792d678..e64bf8f8 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -924,6 +924,7 @@ connection_close_error (struct MHD_Connection *connection, | |||
924 | const char *emsg) | 924 | const char *emsg) |
925 | { | 925 | { |
926 | connection->stop_with_error = true; | 926 | connection->stop_with_error = true; |
927 | connection->early_response = true; | ||
927 | #ifdef HAVE_MESSAGES | 928 | #ifdef HAVE_MESSAGES |
928 | if (NULL != emsg) | 929 | if (NULL != emsg) |
929 | MHD_DLOG (connection->daemon, | 930 | MHD_DLOG (connection->daemon, |
@@ -1294,14 +1295,13 @@ keepalive_possible (struct MHD_Connection *connection) | |||
1294 | mhd_assert (0 == (r->flags_auto & MHD_RAF_HAS_CONNECTION_CLOSE)); | 1295 | mhd_assert (0 == (r->flags_auto & MHD_RAF_HAS_CONNECTION_CLOSE)); |
1295 | /* Valid HTTP version is enforced by 'MHD_queue_response()' */ | 1296 | /* Valid HTTP version is enforced by 'MHD_queue_response()' */ |
1296 | mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (c->http_ver)); | 1297 | mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (c->http_ver)); |
1297 | /* TODO: Enable assert when MHD will allow early response */ | 1298 | mhd_assert (! c->stop_with_error); |
1298 | /* TODO: Add 'early_response' */ | ||
1299 | /* mhd_assert (! c->stop_with_error); */ | ||
1300 | return MHD_CONN_MUST_UPGRADE; | 1299 | return MHD_CONN_MUST_UPGRADE; |
1301 | } | 1300 | } |
1302 | #endif /* UPGRADE_SUPPORT */ | 1301 | #endif /* UPGRADE_SUPPORT */ |
1303 | 1302 | ||
1304 | if ((c->read_closed) || (c->stop_with_error)) | 1303 | mhd_assert ( (! c->stop_with_error) || (c->early_response)); |
1304 | if ((c->read_closed) || (c->early_response)) | ||
1305 | return MHD_CONN_MUST_CLOSE; | 1305 | return MHD_CONN_MUST_CLOSE; |
1306 | 1306 | ||
1307 | if (0 != (r->flags & MHD_RF_HTTP_1_0_COMPATIBLE_STRICT)) | 1307 | if (0 != (r->flags & MHD_RF_HTTP_1_0_COMPATIBLE_STRICT)) |
@@ -2256,7 +2256,7 @@ transmit_error_response_len (struct MHD_Connection *connection, | |||
2256 | struct MHD_Response *response; | 2256 | struct MHD_Response *response; |
2257 | enum MHD_Result iret; | 2257 | enum MHD_Result iret; |
2258 | 2258 | ||
2259 | mhd_assert (! connection->stop_with_error); /* Send error one time only */ | 2259 | mhd_assert (! connection->stop_with_error); /* Do not send error twice */ |
2260 | if (connection->stop_with_error) | 2260 | if (connection->stop_with_error) |
2261 | { /* Should not happen */ | 2261 | { /* Should not happen */ |
2262 | if (MHD_CONNECTION_CLOSED > connection->state) | 2262 | if (MHD_CONNECTION_CLOSED > connection->state) |
@@ -2265,6 +2265,7 @@ transmit_error_response_len (struct MHD_Connection *connection, | |||
2265 | return; | 2265 | return; |
2266 | } | 2266 | } |
2267 | connection->stop_with_error = true; | 2267 | connection->stop_with_error = true; |
2268 | connection->early_response = true; | ||
2268 | #ifdef HAVE_MESSAGES | 2269 | #ifdef HAVE_MESSAGES |
2269 | MHD_DLOG (connection->daemon, | 2270 | MHD_DLOG (connection->daemon, |
2270 | _ ("Error processing request (HTTP response code is %u ('%s')). " \ | 2271 | _ ("Error processing request (HTTP response code is %u ('%s')). " \ |
@@ -2435,7 +2436,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2435 | REQUEST_TOO_BIG); | 2436 | REQUEST_TOO_BIG); |
2436 | continue; | 2437 | continue; |
2437 | } | 2438 | } |
2438 | if (! connection->stop_with_error) | 2439 | if (! connection->early_response) |
2439 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | 2440 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; |
2440 | else | 2441 | else |
2441 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | 2442 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; |
@@ -2475,7 +2476,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2475 | } | 2476 | } |
2476 | } | 2477 | } |
2477 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && | 2478 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && |
2478 | (! connection->stop_with_error) ) | 2479 | (! connection->early_response) ) |
2479 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | 2480 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; |
2480 | else | 2481 | else |
2481 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | 2482 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; |
@@ -4175,6 +4176,7 @@ connection_reset (struct MHD_Connection *connection, | |||
4175 | /* Reset connection to process the next request */ | 4176 | /* Reset connection to process the next request */ |
4176 | size_t new_read_buf_size; | 4177 | size_t new_read_buf_size; |
4177 | mhd_assert (! c->stop_with_error); | 4178 | mhd_assert (! c->stop_with_error); |
4179 | mhd_assert (! c->early_response); | ||
4178 | 4180 | ||
4179 | if ( (NULL != d->notify_completed) && | 4181 | if ( (NULL != d->notify_completed) && |
4180 | (c->client_aware) ) | 4182 | (c->client_aware) ) |
@@ -4391,7 +4393,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4391 | /* we refused (no upload allowed!) */ | 4393 | /* we refused (no upload allowed!) */ |
4392 | connection->remaining_upload_size = 0; | 4394 | connection->remaining_upload_size = 0; |
4393 | /* force close, in case client still tries to upload... */ | 4395 | /* force close, in case client still tries to upload... */ |
4394 | connection->stop_with_error = true; | 4396 | connection->early_response = true; |
4395 | } | 4397 | } |
4396 | connection->state = (0 == connection->remaining_upload_size) | 4398 | connection->state = (0 == connection->remaining_upload_size) |
4397 | ? MHD_CONNECTION_FULL_REQ_RECEIVED | 4399 | ? MHD_CONNECTION_FULL_REQ_RECEIVED |
@@ -4417,10 +4419,10 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4417 | if ( (0 == connection->remaining_upload_size) || | 4419 | if ( (0 == connection->remaining_upload_size) || |
4418 | ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) && | 4420 | ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) && |
4419 | (0 == connection->read_buffer_offset) && | 4421 | (0 == connection->read_buffer_offset) && |
4420 | (connection->stop_with_error) ) ) | 4422 | (connection->early_response) ) ) |
4421 | { | 4423 | { |
4422 | if ( (connection->have_chunked_upload) && | 4424 | if ( (connection->have_chunked_upload) && |
4423 | (! connection->stop_with_error) ) | 4425 | (! connection->early_response) ) |
4424 | connection->state = MHD_CONNECTION_BODY_RECEIVED; | 4426 | connection->state = MHD_CONNECTION_BODY_RECEIVED; |
4425 | else | 4427 | else |
4426 | connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED; | 4428 | connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED; |
@@ -4659,7 +4661,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4659 | connection_reset (connection, | 4661 | connection_reset (connection, |
4660 | MHD_CONN_USE_KEEPALIVE == connection->keepalive && | 4662 | MHD_CONN_USE_KEEPALIVE == connection->keepalive && |
4661 | ! connection->read_closed && | 4663 | ! connection->read_closed && |
4662 | ! connection->stop_with_error); | 4664 | ! connection->early_response); |
4663 | continue; | 4665 | continue; |
4664 | case MHD_CONNECTION_CLOSED: | 4666 | case MHD_CONNECTION_CLOSED: |
4665 | cleanup_connection (connection); | 4667 | cleanup_connection (connection); |
@@ -5087,7 +5089,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5087 | { | 5089 | { |
5088 | /* response was queued "early", refuse to read body / footers or | 5090 | /* response was queued "early", refuse to read body / footers or |
5089 | further requests! */ | 5091 | further requests! */ |
5090 | connection->stop_with_error = true; | 5092 | connection->early_response = true; |
5091 | connection->state = MHD_CONNECTION_START_REPLY; | 5093 | connection->state = MHD_CONNECTION_START_REPLY; |
5092 | connection->remaining_upload_size = 0; | 5094 | connection->remaining_upload_size = 0; |
5093 | } | 5095 | } |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 28ec66e2..b2bd0f6c 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1220,11 +1220,17 @@ struct MHD_Connection | |||
1220 | * The error may come from the client side (like wrong request format), | 1220 | * The error may come from the client side (like wrong request format), |
1221 | * from the application side (like data callback returned error), or from | 1221 | * from the application side (like data callback returned error), or from |
1222 | * the OS side (like out-of-memory). | 1222 | * the OS side (like out-of-memory). |
1223 | */ | ||
1224 | bool stop_with_error; | ||
1225 | |||
1226 | /** | ||
1227 | * Response queued early, before the request is fully processed, | ||
1228 | * the client upload is rejected. | ||
1223 | * The connection cannot be reused for additional requests as the current | 1229 | * The connection cannot be reused for additional requests as the current |
1224 | * request may be incompletely read and it is unclear where is the initial | 1230 | * request is incompletely read and it is unclear where is the initial |
1225 | * byte of the next request. | 1231 | * byte of the next request. |
1226 | */ | 1232 | */ |
1227 | bool stop_with_error; | 1233 | bool early_response; |
1228 | 1234 | ||
1229 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 1235 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
1230 | /** | 1236 | /** |