Skip to content

Commit 3d887e8

Browse files
net: lib: http: allow configuring response chunk size
Introduce Kconfig HTTP_SERVER_STATIC_FS_RESPONSE_SIZE, size of individual chunks when serving files. Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
1 parent 0f8b7b7 commit 3d887e8

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

doc/connectivity/networking/api/http_server.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ content type text/html.
261261
262262
HTTP_SERVER_CONTENT_TYPE(json, "application/json")
263263
264+
When serving files from a static filesystem, the response chunk size can be configured
265+
using the :kconfig:option:`CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE` Kconfig option.
266+
This determines the size of individual chunks when transmitting file content to clients.
267+
264268
Dynamic resources
265269
=================
266270

subsys/net/lib/http/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if HTTP_SERVER
4444

4545
config HTTP_SERVER_STACK_SIZE
4646
int "HTTP server thread stack size"
47+
default 4096 if FILE_SYSTEM
4748
default 3072
4849
help
4950
HTTP server thread stack size for processing RX/TX events.
@@ -219,6 +220,17 @@ config HTTP_SERVER_COMPRESSION
219220
5. deflate -> .zz
220221
6. File without compression
221222

223+
config HTTP_SERVER_STATIC_FS_RESPONSE_SIZE
224+
int "Size of static file system response buffer"
225+
depends on FILE_SYSTEM
226+
default 1024
227+
help
228+
The size of a single chunk when serving static files from the file system.
229+
This config value must be large enough to hold the headers in a single chunk.
230+
If set to 0, the server will use the minimal viable buffer size for the response.
231+
Please note that it is allocated on the stack of the HTTP server thread,
232+
so CONFIG_HTTP_SERVER_STACK_SIZE has to be sufficiently large.
233+
222234
endif
223235

224236
# Hidden option to avoid having multiple individual options that are ORed together

subsys/net/lib/http/http_server_http1.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,19 @@ int handle_http1_static_fs_resource(struct http_resource_detail_static_fs *stati
482482
sizeof("Content-Length: 01234567890123456789\r\n")
483483
#define CONTENT_ENCODING_HEADER_SIZE \
484484
sizeof(CONTENT_ENCODING_HEADER) + HTTP_COMPRESSION_MAX_STRING_LEN + sizeof("\r\n")
485+
/* Calculate the minimum size required for the headers */
485486
#define STATIC_FS_RESPONSE_SIZE \
486487
COND_CODE_1( \
487488
IS_ENABLED(CONFIG_HTTP_SERVER_COMPRESSION), \
488489
(STATIC_FS_RESPONSE_BASE_SIZE + CONTENT_ENCODING_HEADER_SIZE), \
489490
(STATIC_FS_RESPONSE_BASE_SIZE))
491+
#if CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE > 0
492+
BUILD_ASSERT(CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE >= STATIC_FS_RESPONSE_SIZE,
493+
"CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE must be at least "
494+
"large enough to hold HTTP headers");
495+
#undef STATIC_FS_RESPONSE_SIZE
496+
#define STATIC_FS_RESPONSE_SIZE CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE
497+
#endif
490498

491499
enum http_compression chosen_compression = 0;
492500
int len;

0 commit comments

Comments
 (0)