[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd2] 14/21: POST parser: optimised large upload processing
From: |
Admin |
Subject: |
[libmicrohttpd2] 14/21: POST parser: optimised large upload processing |
Date: |
Fri, 13 Jun 2025 23:38:22 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd2.
commit c36e910f5689c94528beabfa3fc619aa09f5a312
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
AuthorDate: Fri Jun 13 16:23:14 2025 +0200
POST parser: optimised large upload processing
---
src/mhd2/post_parser_funcs.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/src/mhd2/post_parser_funcs.c b/src/mhd2/post_parser_funcs.c
index 1095829..97317fb 100644
--- a/src/mhd2/post_parser_funcs.c
+++ b/src/mhd2/post_parser_funcs.c
@@ -1457,6 +1457,36 @@ parse_post_mpart (struct MHD_Connection *restrict c,
mhd_assert (mhd_POST_INVALID_POS == mf->line_start);
do /* Fast local loop */
{
+#ifndef MHD_FAVOR_SMALL_CODE
+ const char *lf_ptr;
+ size_t lf_pos;
+
+ lf_ptr = (const char *) memchr (buf + i, '\n', *pdata_size - i);
+ if (NULL == lf_ptr)
+ {
+ if ('\r' == buf[*pdata_size - 1])
+ mf->st = mhd_POST_MPART_ST_PREAMBL_CR_FOUND;
+ i = *pdata_size;
+ break;
+ }
+ lf_pos = (size_t) (lf_ptr - buf);
+ mhd_assert (i <= lf_pos);
+ mhd_assert (*pdata_size > i);
+ if (bare_lf_as_crlf)
+ {
+ i = lf_pos + 1;
+ mf->st = mhd_POST_MPART_ST_PREAMBL_LINE_START;
+ break;
+ }
+ else if ((i < lf_pos) &&
+ ('\r' == buf[lf_pos - 1]))
+ {
+ i = lf_pos + 1;
+ mf->st = mhd_POST_MPART_ST_PREAMBL_LINE_START;
+ break;
+ }
+ i = lf_pos;
+#else /* MHD_FAVOR_SMALL_CODE */
if ('\r' == buf[i])
{
mf->st = mhd_POST_MPART_ST_PREAMBL_CR_FOUND;
@@ -1469,6 +1499,7 @@ parse_post_mpart (struct MHD_Connection *restrict c,
++i; /* Go to the next char */
break;
}
+#endif /* MHD_FAVOR_SMALL_CODE */
} while (*pdata_size > ++i);
mhd_assert ((*pdata_size == i) || \
(mhd_POST_MPART_ST_PREAMBL_CR_FOUND == mf->st) || \
@@ -1496,6 +1527,21 @@ parse_post_mpart (struct MHD_Connection *restrict c,
mhd_assert (mhd_POST_INVALID_POS == mf->delim_check_start);
mhd_assert (mhd_POST_INVALID_POS == mf->line_start);
mf->line_start = i;
+#ifndef MHD_FAVOR_SMALL_CODE
+ if (*pdata_size - i >= mf->bound.size + 2)
+ {
+ if (('-' == buf[i]) &&
+ ('-' == buf[i + 1]) &&
+ (0 == memcmp (buf + i + 2, mf->bound.data, mf->bound.size)))
+ {
+ mf->st = mhd_POST_MPART_ST_FIRST_DELIM_FOUND;
+ i += 2 + mf->bound.size + 1;
+ }
+ else
+ mf->st = mhd_POST_MPART_ST_BACK_TO_PREAMBL;
+ continue;
+ }
+#endif /* ! MHD_FAVOR_SMALL_CODE */
mf->st = mhd_POST_MPART_ST_PREAMBL_CHECKING_FOR_DELIM;
mhd_FALLTHROUGH;
/* Intentional fallthrough */
@@ -1877,6 +1923,38 @@ parse_post_mpart (struct MHD_Connection *restrict c,
mhd_assert (mhd_POST_INVALID_POS != p_data->field_start);
do /* Fast local loop */
{
+#ifndef MHD_FAVOR_SMALL_CODE
+ const char *lf_ptr;
+ size_t lf_pos;
+
+ lf_ptr = (const char *) memchr (buf + i, '\n', *pdata_size - i);
+ if (NULL == lf_ptr)
+ {
+ if ('\r' == buf[*pdata_size - 1])
+ mf->st = mhd_POST_MPART_ST_VALUE_CR_FOUND;
+ i = *pdata_size;
+ break;
+ }
+ lf_pos = (size_t) (lf_ptr - buf);
+ mhd_assert (i <= lf_pos);
+ mhd_assert (*pdata_size > i);
+ if ((i < lf_pos) &&
+ ('\r' == buf[lf_pos - 1]))
+ {
+ mf->delim_check_start = lf_pos - 1;
+ mf->st = mhd_POST_MPART_ST_VALUE_LINE_START;
+ i = lf_pos + 1;
+ break;
+ }
+ else if (bare_lf_as_crlf)
+ {
+ mf->delim_check_start = lf_pos;
+ mf->st = mhd_POST_MPART_ST_VALUE_LINE_START;
+ i = lf_pos + 1;
+ break;
+ }
+ i = lf_pos;
+#else /* MHD_FAVOR_SMALL_CODE */
if ('\r' == buf[i])
{
mf->delim_check_start = i;
@@ -1891,6 +1969,7 @@ parse_post_mpart (struct MHD_Connection *restrict c,
++i;
break;
}
+#endif /* MHD_FAVOR_SMALL_CODE */
} while (*pdata_size > ++i);
mhd_assert ((*pdata_size == i) || \
(mhd_POST_MPART_ST_VALUE_CR_FOUND == mf->st) || \
@@ -1909,6 +1988,21 @@ parse_post_mpart (struct MHD_Connection *restrict c,
mhd_assert (mhd_POST_INVALID_POS != mf->delim_check_start);
mhd_assert (mhd_POST_INVALID_POS != p_data->field_start);
mf->line_start = i;
+#ifndef MHD_FAVOR_SMALL_CODE
+ if (*pdata_size - i >= mf->bound.size + 2)
+ {
+ if (('-' == buf[i]) &&
+ ('-' == buf[i + 1]) &&
+ (0 == memcmp (buf + i + 2, mf->bound.data, mf->bound.size)))
+ {
+ mf->st = mhd_POST_MPART_ST_DELIM_FOUND;
+ i += 2 + mf->bound.size;
+ }
+ else
+ mf->st = mhd_POST_MPART_ST_BACK_TO_VALUE;
+ continue;
+ }
+#endif /* ! MHD_FAVOR_SMALL_CODE */
mf->st = mhd_POST_MPART_ST_VALUE_CHECKING_FOR_DELIM;
mhd_FALLTHROUGH;
/* Intentional fallthrough */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd2] 13/21: parse_http_std_method(): optimised, (continued)
- [libmicrohttpd2] 13/21: parse_http_std_method(): optimised, Admin, 2025/06/13
- [libmicrohttpd2] 21/21: perf_replies: added response sizes 8 MiB and 101 MiB, Admin, 2025/06/13
- [libmicrohttpd2] 02/21: bootstrap: make sure that pre-commit hook really used, Admin, 2025/06/13
- [libmicrohttpd2] 01/21: conn_data_send.c: fixed large sending, added some asserts, Admin, 2025/06/13
- [libmicrohttpd2] 04/21: xdigittovalue(): optimised., Admin, 2025/06/13
- [libmicrohttpd2] 18/21: Renamed test_postprocessor -> test_postparser to match API naming, Admin, 2025/06/13
- [libmicrohttpd2] 16/21: configure: minor check improvement, Admin, 2025/06/13
- [libmicrohttpd2] 12/21: mhd_locks: added W32 implementation based on SRW locks (and minor improvements), Admin, 2025/06/13
- [libmicrohttpd2] 10/21: configure: added release build linker flags, Admin, 2025/06/13
- [libmicrohttpd2] 15/21: POST parser: improved parsing performance by storing complete delimiter instead of boundary, Admin, 2025/06/13
- [libmicrohttpd2] 14/21: POST parser: optimised large upload processing,
Admin <=
- [libmicrohttpd2] 07/21: daemon_start: cosmetics, fixed code style, Admin, 2025/06/13
- [libmicrohttpd2] 06/21: Fixed compiler warnings, Admin, 2025/06/13
- [libmicrohttpd2] 08/21: mhd_str: added functions attributes, fixed doxy, removed extra checks in functions, Admin, 2025/06/13
- [libmicrohttpd2] 03/21: bootstrap: English fixes, Admin, 2025/06/13
- [libmicrohttpd2] 05/21: mhd_str.c: minor readability improvements, Admin, 2025/06/13
- [libmicrohttpd2] 20/21: perf_replies: fixed formatting, Admin, 2025/06/13
- [libmicrohttpd2] 19/21: conn_data_send.c: fixed formatting, Admin, 2025/06/13
- [libmicrohttpd2] 17/21: POST parser: accelerate by using memmem() for delimiters, Admin, 2025/06/13