[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] branch master updated (149eaabc -> e8e4d70c)
From: |
gnunet |
Subject: |
[libmicrohttpd] branch master updated (149eaabc -> e8e4d70c) |
Date: |
Tue, 08 Jun 2021 08:58:17 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a change to branch master
in repository libmicrohttpd.
from 149eaabc Added TODO comments and corrected log message
new 7d53b1eb try_ready_chunked_body: handle large chunks properly
new 2106f6f2 connection.c: added TODO comment
new 45c7e2bc MHD_queue_response: check whether provided status code is a
three digits code
new b0400609 keepalive_possible: do not use "Keep-Alive" with read-closed
connections
new e8e4d70c Response: disallow two "Transfer-Encoding" headers
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/microhttpd/connection.c | 33 +++++++++++++++++++++++++++------
src/microhttpd/response.c | 17 ++++++++++-------
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 044b9a01..cf22f41b 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -993,7 +993,8 @@ try_ready_chunked_body (struct MHD_Connection *connection)
{
ssize_t ret;
struct MHD_Response *response;
- char cbuf[10]; /* 10: max strlen of "%x\r\n" */
+ static const size_t max_chunk = 0xFFFFFF;
+ char cbuf[10]; /* 10: max strlen of "FFFFFF\r\n" */
int cblen;
response = connection->response;
@@ -1014,8 +1015,8 @@ try_ready_chunked_body (struct MHD_Connection *connection)
_ ("Closing connection (out of memory)."));
return MHD_NO;
}
- if ( (2 * (0xFFFFFF + sizeof(cbuf) + 2)) < size)
- size = 2 * (0xFFFFFF + sizeof(cbuf) + 2);
+ if ( (max_chunk + sizeof(cbuf) + 2) < size)
+ size = max_chunk + sizeof(cbuf) + 2;
connection->write_buffer = MHD_pool_allocate (connection->pool,
size,
false);
@@ -1045,10 +1046,15 @@ try_ready_chunked_body (struct MHD_Connection
*connection)
else
{
/* buffer not in range, try to fill it */
+ size_t size_to_fill;
+
+ size_to_fill = connection->write_buffer_size - sizeof (cbuf) - 2;
+ if (max_chunk < size_to_fill)
+ size_to_fill = max_chunk;
ret = response->crc (response->crc_cls,
connection->response_write_position,
&connection->write_buffer[sizeof (cbuf)],
- connection->write_buffer_size - sizeof (cbuf) - 2);
+ size_to_fill);
}
if ( ((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret)
{
@@ -1082,8 +1088,6 @@ try_ready_chunked_body (struct MHD_Connection *connection)
#endif
return MHD_NO;
}
- if (ret > 0xFFFFFF)
- ret = 0xFFFFFF;
cblen = MHD_snprintf_ (cbuf,
sizeof (cbuf),
"%X\r\n",
@@ -1124,6 +1128,9 @@ keepalive_possible (struct MHD_Connection *connection)
{
if (MHD_CONN_MUST_CLOSE == connection->keepalive)
return MHD_NO;
+ /* TODO: use additional flags, like "error_closure" */
+ if (connection->read_closed)
+ return MHD_NO;
if ( (NULL != connection->response) &&
(0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) )
return MHD_NO;
@@ -2631,6 +2638,9 @@ check_write_done (struct MHD_Connection *connection,
connection->write_buffer_append_offset = 0;
connection->write_buffer_send_offset = 0;
connection->state = next_state;
+ /* TODO: avoid deallocation of the buffer so
+ * it can be reused for chunked body sending when
+ * header has been sent */
MHD_pool_reallocate (connection->pool,
connection->write_buffer,
connection->write_buffer_size,
@@ -4227,6 +4237,17 @@ MHD_queue_response (struct MHD_Connection *connection,
return MHD_NO;
}
#endif /* UPGRADE_SUPPORT */
+ if ( (100 > (status_code & (~MHD_ICY_FLAG))) ||
+ (999 < (status_code & (~MHD_ICY_FLAG))) )
+ {
+#ifdef HAVE_MESSAGES
+ MHD_DLOG (daemon,
+ _ ("Refused wrong status code (%u). " \
+ "HTTP required three digits status code!\n"),
+ (status_code & (~MHD_ICY_FLAG)));
+#endif
+ return MHD_NO;
+ }
MHD_increment_response_rc (response);
connection->response = response;
connection->responseCode = status_code;
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index bf78d735..eb29ab64 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -135,18 +135,21 @@ MHD_add_response_header (struct MHD_Response *response,
const char *header,
const char *content)
{
- if ( (MHD_str_equal_caseless_ (header,
- MHD_HTTP_HEADER_TRANSFER_ENCODING)) &&
- (! MHD_str_equal_caseless_ (content,
- "identity")) &&
- (! MHD_str_equal_caseless_ (content,
- "chunked")) )
+ if (MHD_str_equal_caseless_ (header,
+ MHD_HTTP_HEADER_TRANSFER_ENCODING))
{
+ /* TODO: remove support for "identity" */
+ /* Only one "Transfer-Encoding" header is allowed */
+ if (NULL !=
+ MHD_get_response_header (response, MHD_HTTP_HEADER_TRANSFER_ENCODING) )
+ return MHD_NO;
/* Setting transfer encodings other than "identity" or
"chunked" is not allowed. Note that MHD will set the
correct transfer encoding if required automatically. */
/* NOTE: for compressed bodies, use the "Content-encoding" header */
- return MHD_NO;
+ if ( (! MHD_str_equal_caseless_ (content, "identity")) &&
+ (! MHD_str_equal_caseless_ (content, "chunked")) )
+ return MHD_NO;
}
if ( (0 == (MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
& response->flags)) &&
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (149eaabc -> e8e4d70c),
gnunet <=
- [libmicrohttpd] 02/05: connection.c: added TODO comment, gnunet, 2021/06/08
- [libmicrohttpd] 05/05: Response: disallow two "Transfer-Encoding" headers, gnunet, 2021/06/08
- [libmicrohttpd] 04/05: keepalive_possible: do not use "Keep-Alive" with read-closed connections, gnunet, 2021/06/08
- [libmicrohttpd] 01/05: try_ready_chunked_body: handle large chunks properly, gnunet, 2021/06/08
- [libmicrohttpd] 03/05: MHD_queue_response: check whether provided status code is a three digits code, gnunet, 2021/06/08