Fixed sending response body for the HEAD requests

Sometimes response body as available but MHD must not send it, like for
HEAD requests. This commit fixed regression caused by usage of
MHD_send_on_connection2_ ().
This commit is contained in:
Evgeny Grin (Karlson2k)
2020-12-12 18:44:15 +03:00
parent 3b435274a2
commit e09b6df63e
2 changed files with 31 additions and 9 deletions
+30 -9
View File
@@ -2920,15 +2920,35 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
mhd_assert (NULL != connection->response);
mhd_assert ( (0 == connection->response->data_size) || \
(0 == connection->response->data_start) );
mhd_assert ( (0 == connection->response_write_position) || \
(response->total_size ==
connection->response_write_position) || \
(MHD_SIZE_UNKNOWN ==
connection->response_write_position) );
/* Send response headers alongside the response body, if the body
* data is available. */
ret = MHD_send_on_connection2_ (connection,
&connection->write_buffer
[connection->write_buffer_send_offset],
wb_ready,
connection->response->data,
connection->response->data_size);
if (0 == connection->response_write_position)
{
/* Send response headers alongside the response body, if the body
* data is available. */
ret = MHD_send_on_connection2_ (connection,
&connection->write_buffer
[connection->write_buffer_send_offset],
wb_ready,
connection->response->data,
connection->response->data_size);
}
else
{
/* This is response for HEAD request or reply body is not allowed
* for any other reason. */
/* Do not send the body data even if it's available. */
ret = MHD_send_on_connection2_ (connection,
&connection->write_buffer
[connection->write_buffer_send_offset],
wb_ready,
NULL,
0);
}
if (ret < 0)
{
@@ -2944,9 +2964,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
{
/* The complete header and some response data have been sent,
* update both offsets. */
mhd_assert (0 == connection->response_write_position);
mhd_assert (! connection->have_chunked_upload);
connection->write_buffer_send_offset += wb_ready;
connection->response_write_position += ret - wb_ready;
connection->response_write_position = ret - wb_ready;
}
else
connection->write_buffer_send_offset += ret;
+1
View File
@@ -841,6 +841,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
const bool no_vec = false;
#endif /* ! HTTPS_SUPPORT */
#endif /* HAVE_SENDMSG || HAVE_WRITEV */
mhd_assert ( (NULL != buffer) || (0 == buffer_size) );
if (
#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)