aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-08-21 14:28:05 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-08-21 14:28:05 +0300
commitd8ea84fd6dfa35ca125ea61d47a35835f32bdd0a (patch)
tree8073a95c83ce1bdc24bebf1609da2ae35e49c563
parent08d144ba1928085cc2e1ecb167ce380cab732b52 (diff)
downloadlibmicrohttpd-d8ea84fd6dfa35ca125ea61d47a35835f32bdd0a.tar.gz
libmicrohttpd-d8ea84fd6dfa35ca125ea61d47a35835f32bdd0a.zip
connection.c: minor updates: used new reply flags, added asserts and TODOs
-rw-r--r--src/microhttpd/connection.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index df17fa61..7db660cb 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -905,9 +905,12 @@ try_ready_normal_body (struct MHD_Connection *connection)
905 struct MHD_Response *response; 905 struct MHD_Response *response;
906 906
907 response = connection->response; 907 response = connection->response;
908 mhd_assert (connection->rp_props.send_reply_body);
909
908 if ( (0 == response->total_size) || 910 if ( (0 == response->total_size) ||
911 /* TODO: replace the next check with assert */
909 (connection->response_write_position == response->total_size) ) 912 (connection->response_write_position == response->total_size) )
910 return MHD_YES; /* 0-byte response is always ready */ 913 return MHD_YES; /* 0-byte response is always ready */
911 if (NULL != response->data_iov) 914 if (NULL != response->data_iov)
912 { 915 {
913 size_t copy_size; 916 size_t copy_size;
@@ -958,6 +961,8 @@ try_ready_normal_body (struct MHD_Connection *connection)
958 (((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) ) 961 (((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) )
959 { 962 {
960 /* either error or http 1.0 transfer, close socket! */ 963 /* either error or http 1.0 transfer, close socket! */
964 /* TODO: do not update total size, check whether response
965 * was really with unknown size */
961 response->total_size = connection->response_write_position; 966 response->total_size = connection->response_write_position;
962#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 967#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
963 MHD_mutex_unlock_chk_ (&response->mutex); 968 MHD_mutex_unlock_chk_ (&response->mutex);
@@ -1094,6 +1099,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
1094 if ( ((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) 1099 if ( ((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret)
1095 { 1100 {
1096 /* error, close socket! */ 1101 /* error, close socket! */
1102 /* TODO: remove update of the response size */
1097 response->total_size = connection->response_write_position; 1103 response->total_size = connection->response_write_position;
1098#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 1104#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1099 MHD_mutex_unlock_chk_ (&response->mutex); 1105 MHD_mutex_unlock_chk_ (&response->mutex);
@@ -3646,13 +3652,18 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3646 connection->response_write_position) || \ 3652 connection->response_write_position) || \
3647 (MHD_SIZE_UNKNOWN == 3653 (MHD_SIZE_UNKNOWN ==
3648 connection->response_write_position) ); 3654 connection->response_write_position) );
3655 mhd_assert ((MHD_CONN_MUST_UPGRADE != connection->keepalive) || \
3656 (! connection->rp_props.send_reply_body));
3649 3657
3650 if ( (NULL == resp->crc) && 3658 if ( (connection->rp_props.send_reply_body) &&
3659 (NULL == resp->crc) &&
3651 (NULL == resp->data_iov) && 3660 (NULL == resp->data_iov) &&
3661 /* TODO: remove the next check as 'send_reply_body' is used */
3652 (0 == connection->response_write_position) && 3662 (0 == connection->response_write_position) &&
3653 (! connection->rp_props.chunked) ) 3663 (! connection->rp_props.chunked) )
3654 { 3664 {
3655 mhd_assert (resp->total_size >= resp->data_size); 3665 mhd_assert (resp->total_size >= resp->data_size);
3666 mhd_assert (0 == resp->data_start);
3656 /* Send response headers alongside the response body, if the body 3667 /* Send response headers alongside the response body, if the body
3657 * data is available. */ 3668 * data is available. */
3658 ret = MHD_send_hdr_and_body_ (connection, 3669 ret = MHD_send_hdr_and_body_ (connection,
@@ -3677,10 +3688,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3677 NULL, 3688 NULL,
3678 0, 3689 0,
3679 ((0 == resp->total_size) || 3690 ((0 == resp->total_size) ||
3680 (resp->total_size == 3691 (! connection->rp_props.send_reply_body)
3681 connection->response_write_position) || 3692 ));
3682 (MHD_SIZE_UNKNOWN ==
3683 connection->response_write_position)));
3684 } 3693 }
3685 3694
3686 if (ret < 0) 3695 if (ret < 0)
@@ -3705,6 +3714,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3705 * update both offsets. */ 3714 * update both offsets. */
3706 mhd_assert (0 == connection->response_write_position); 3715 mhd_assert (0 == connection->response_write_position);
3707 mhd_assert (! connection->rp_props.chunked); 3716 mhd_assert (! connection->rp_props.chunked);
3717 mhd_assert (connection->rp_props.send_reply_body);
3708 connection->write_buffer_send_offset += wb_ready; 3718 connection->write_buffer_send_offset += wb_ready;
3709 connection->response_write_position = ret - wb_ready; 3719 connection->response_write_position = ret - wb_ready;
3710 } 3720 }
@@ -4863,6 +4873,8 @@ MHD_queue_response (struct MHD_Connection *connection,
4863 /* if this is a "HEAD" request, or a status code for 4873 /* if this is a "HEAD" request, or a status code for
4864 which a body is not allowed, pretend that we 4874 which a body is not allowed, pretend that we
4865 have already sent the full message body. */ 4875 have already sent the full message body. */
4876 /* TODO: remove the next assignment, use 'rp_props.send_reply_body' in
4877 * checks */
4866 connection->response_write_position = response->total_size; 4878 connection->response_write_position = response->total_size;
4867 } 4879 }
4868 if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) 4880 if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state)