diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-11-13 13:44:23 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-11-21 22:06:19 +0300 |
commit | a761eb67b6e996003ed34bce3f35b4d9d437ad86 (patch) | |
tree | c8c2317290373c8c95b74374da887ede7ce074ae | |
parent | 025d2ab1b3f2a3ecffc029924a5e36a53b6bab00 (diff) | |
download | libmicrohttpd-a761eb67b6e996003ed34bce3f35b4d9d437ad86.tar.gz libmicrohttpd-a761eb67b6e996003ed34bce3f35b4d9d437ad86.zip |
Reworking early close flags
'early_response' renamed to 'discard_request'.
Changed the way how flags are checked.
-rw-r--r-- | src/microhttpd/connection.c | 44 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 2 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index a068bfe4..390181ec 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -924,7 +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 | connection->discard_request = true; |
928 | #ifdef HAVE_MESSAGES | 928 | #ifdef HAVE_MESSAGES |
929 | if (NULL != emsg) | 929 | if (NULL != emsg) |
930 | MHD_DLOG (connection->daemon, | 930 | MHD_DLOG (connection->daemon, |
@@ -1300,8 +1300,8 @@ keepalive_possible (struct MHD_Connection *connection) | |||
1300 | } | 1300 | } |
1301 | #endif /* UPGRADE_SUPPORT */ | 1301 | #endif /* UPGRADE_SUPPORT */ |
1302 | 1302 | ||
1303 | mhd_assert ( (! c->stop_with_error) || (c->early_response)); | 1303 | mhd_assert ( (! c->stop_with_error) || (c->discard_request)); |
1304 | if ((c->read_closed) || (c->early_response)) | 1304 | if ((c->read_closed) || (c->discard_request)) |
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)) |
@@ -2265,7 +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 | connection->discard_request = true; |
2269 | #ifdef HAVE_MESSAGES | 2269 | #ifdef HAVE_MESSAGES |
2270 | MHD_DLOG (connection->daemon, | 2270 | MHD_DLOG (connection->daemon, |
2271 | _ ("Error processing request (HTTP response code is %u ('%s')). " \ | 2271 | _ ("Error processing request (HTTP response code is %u ('%s')). " \ |
@@ -2436,7 +2436,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2436 | REQUEST_TOO_BIG); | 2436 | REQUEST_TOO_BIG); |
2437 | continue; | 2437 | continue; |
2438 | } | 2438 | } |
2439 | if (! connection->early_response) | 2439 | if (! connection->discard_request) |
2440 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | 2440 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; |
2441 | else | 2441 | else |
2442 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | 2442 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; |
@@ -2476,7 +2476,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2476 | } | 2476 | } |
2477 | } | 2477 | } |
2478 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && | 2478 | if ( (connection->read_buffer_offset < connection->read_buffer_size) && |
2479 | (! connection->early_response) ) | 2479 | (! connection->discard_request) ) |
2480 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; | 2480 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ; |
2481 | else | 2481 | else |
2482 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; | 2482 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK; |
@@ -2485,7 +2485,7 @@ MHD_connection_update_event_loop_info (struct MHD_Connection *connection) | |||
2485 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: | 2485 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: |
2486 | /* while reading footers, we always grow the | 2486 | /* while reading footers, we always grow the |
2487 | read buffer if needed, no size-check required */ | 2487 | read buffer if needed, no size-check required */ |
2488 | if (connection->stop_with_error) | 2488 | if (connection->read_closed) |
2489 | { | 2489 | { |
2490 | CONNECTION_CLOSE_ERROR (connection, | 2490 | CONNECTION_CLOSE_ERROR (connection, |
2491 | NULL); | 2491 | NULL); |
@@ -3694,8 +3694,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
3694 | case MHD_CONNECTION_BODY_RECEIVED: | 3694 | case MHD_CONNECTION_BODY_RECEIVED: |
3695 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: | 3695 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: |
3696 | /* nothing to do but default action */ | 3696 | /* nothing to do but default action */ |
3697 | if ((connection->read_closed) || (connection->stop_with_error)) | 3697 | if (connection->read_closed) |
3698 | { | 3698 | { |
3699 | /* TODO: check whether this really needed */ | ||
3699 | MHD_connection_close_ (connection, | 3700 | MHD_connection_close_ (connection, |
3700 | MHD_REQUEST_TERMINATED_READ_ERROR); | 3701 | MHD_REQUEST_TERMINATED_READ_ERROR); |
3701 | } | 3702 | } |
@@ -4176,7 +4177,7 @@ connection_reset (struct MHD_Connection *connection, | |||
4176 | /* Reset connection to process the next request */ | 4177 | /* Reset connection to process the next request */ |
4177 | size_t new_read_buf_size; | 4178 | size_t new_read_buf_size; |
4178 | mhd_assert (! c->stop_with_error); | 4179 | mhd_assert (! c->stop_with_error); |
4179 | mhd_assert (! c->early_response); | 4180 | mhd_assert (! c->discard_request); |
4180 | 4181 | ||
4181 | if ( (NULL != d->notify_completed) && | 4182 | if ( (NULL != d->notify_completed) && |
4182 | (c->client_aware) ) | 4183 | (c->client_aware) ) |
@@ -4299,7 +4300,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4299 | continue; | 4300 | continue; |
4300 | } | 4301 | } |
4301 | /* NULL means we didn't get a full line yet */ | 4302 | /* NULL means we didn't get a full line yet */ |
4302 | if (connection->stop_with_error) | 4303 | if (connection->discard_request) |
4303 | { | 4304 | { |
4304 | mhd_assert (MHD_CONNECTION_INIT != connection->state); | 4305 | mhd_assert (MHD_CONNECTION_INIT != connection->state); |
4305 | continue; | 4306 | continue; |
@@ -4314,7 +4315,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4314 | { | 4315 | { |
4315 | if (MHD_CONNECTION_URL_RECEIVED != connection->state) | 4316 | if (MHD_CONNECTION_URL_RECEIVED != connection->state) |
4316 | continue; | 4317 | continue; |
4317 | if (connection->stop_with_error) | 4318 | if (connection->read_closed) |
4318 | { | 4319 | { |
4319 | CONNECTION_CLOSE_ERROR (connection, | 4320 | CONNECTION_CLOSE_ERROR (connection, |
4320 | NULL); | 4321 | NULL); |
@@ -4346,7 +4347,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4346 | { | 4347 | { |
4347 | if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED) | 4348 | if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED) |
4348 | continue; | 4349 | continue; |
4349 | if (connection->stop_with_error) | 4350 | if (connection->read_closed) |
4350 | { | 4351 | { |
4351 | CONNECTION_CLOSE_ERROR (connection, | 4352 | CONNECTION_CLOSE_ERROR (connection, |
4352 | NULL); | 4353 | NULL); |
@@ -4393,7 +4394,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4393 | /* we refused (no upload allowed!) */ | 4394 | /* we refused (no upload allowed!) */ |
4394 | connection->remaining_upload_size = 0; | 4395 | connection->remaining_upload_size = 0; |
4395 | /* force close, in case client still tries to upload... */ | 4396 | /* force close, in case client still tries to upload... */ |
4396 | connection->early_response = true; | 4397 | connection->discard_request = true; |
4397 | } | 4398 | } |
4398 | connection->state = (0 == connection->remaining_upload_size) | 4399 | connection->state = (0 == connection->remaining_upload_size) |
4399 | ? MHD_CONNECTION_FULL_REQ_RECEIVED | 4400 | ? MHD_CONNECTION_FULL_REQ_RECEIVED |
@@ -4413,16 +4414,19 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4413 | if (0 != connection->read_buffer_offset) | 4414 | if (0 != connection->read_buffer_offset) |
4414 | { | 4415 | { |
4415 | process_request_body (connection); /* loop call */ | 4416 | process_request_body (connection); /* loop call */ |
4416 | if (connection->stop_with_error) | 4417 | if (connection->discard_request) |
4418 | { | ||
4419 | mhd_assert (MHD_CONNECTION_CONTINUE_SENT != connection->state); | ||
4417 | continue; | 4420 | continue; |
4421 | } | ||
4418 | } | 4422 | } |
4419 | if ( (0 == connection->remaining_upload_size) || | 4423 | if ( (0 == connection->remaining_upload_size) || |
4420 | ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) && | 4424 | ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) && |
4421 | (0 == connection->read_buffer_offset) && | 4425 | (0 == connection->read_buffer_offset) && |
4422 | (connection->early_response) ) ) | 4426 | (connection->discard_request) ) ) |
4423 | { | 4427 | { |
4424 | if ( (connection->have_chunked_upload) && | 4428 | if ( (connection->have_chunked_upload) && |
4425 | (! connection->early_response) ) | 4429 | (! connection->discard_request) ) |
4426 | connection->state = MHD_CONNECTION_BODY_RECEIVED; | 4430 | connection->state = MHD_CONNECTION_BODY_RECEIVED; |
4427 | else | 4431 | else |
4428 | connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED; | 4432 | connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED; |
@@ -4438,7 +4442,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4438 | { | 4442 | { |
4439 | if (connection->state != MHD_CONNECTION_BODY_RECEIVED) | 4443 | if (connection->state != MHD_CONNECTION_BODY_RECEIVED) |
4440 | continue; | 4444 | continue; |
4441 | if (connection->stop_with_error) | 4445 | if (connection->read_closed) |
4442 | { | 4446 | { |
4443 | CONNECTION_CLOSE_ERROR (connection, | 4447 | CONNECTION_CLOSE_ERROR (connection, |
4444 | NULL); | 4448 | NULL); |
@@ -4472,7 +4476,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4472 | { | 4476 | { |
4473 | if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED) | 4477 | if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED) |
4474 | continue; | 4478 | continue; |
4475 | if (connection->stop_with_error) | 4479 | if (connection->read_closed) |
4476 | { | 4480 | { |
4477 | CONNECTION_CLOSE_ERROR (connection, | 4481 | CONNECTION_CLOSE_ERROR (connection, |
4478 | NULL); | 4482 | NULL); |
@@ -4661,7 +4665,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4661 | connection_reset (connection, | 4665 | connection_reset (connection, |
4662 | MHD_CONN_USE_KEEPALIVE == connection->keepalive && | 4666 | MHD_CONN_USE_KEEPALIVE == connection->keepalive && |
4663 | ! connection->read_closed && | 4667 | ! connection->read_closed && |
4664 | ! connection->early_response); | 4668 | ! connection->discard_request); |
4665 | continue; | 4669 | continue; |
4666 | case MHD_CONNECTION_CLOSED: | 4670 | case MHD_CONNECTION_CLOSED: |
4667 | cleanup_connection (connection); | 4671 | cleanup_connection (connection); |
@@ -5096,7 +5100,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5096 | { | 5100 | { |
5097 | /* response was queued "early", refuse to read body / footers or | 5101 | /* response was queued "early", refuse to read body / footers or |
5098 | further requests! */ | 5102 | further requests! */ |
5099 | connection->early_response = true; | 5103 | connection->discard_request = true; |
5100 | connection->state = MHD_CONNECTION_START_REPLY; | 5104 | connection->state = MHD_CONNECTION_START_REPLY; |
5101 | connection->remaining_upload_size = 0; | 5105 | connection->remaining_upload_size = 0; |
5102 | } | 5106 | } |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index b2bd0f6c..da981c80 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1230,7 +1230,7 @@ struct MHD_Connection | |||
1230 | * request is incompletely read and it is unclear where is the initial | 1230 | * request is incompletely read and it is unclear where is the initial |
1231 | * byte of the next request. | 1231 | * byte of the next request. |
1232 | */ | 1232 | */ |
1233 | bool early_response; | 1233 | bool discard_request; |
1234 | 1234 | ||
1235 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 1235 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
1236 | /** | 1236 | /** |