Skip to content

Commit c562616

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 c562616

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

subsys/net/lib/http/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ config HTTP_SERVER_COMPRESSION
219219
5. deflate -> .zz
220220
6. File without compression
221221

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

224234
# 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+
#ifdef CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE
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)