# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

config HTTP_PARSER
	bool "HTTP Parser support"
	select HTTP_PARSER_URL
	help
	  This option enables the http_parser library from nodejs.
	  This parser requires some string-related routines commonly
	  provided by a libc implementation.

config HTTP_PARSER_URL
	bool "HTTP Parser for URL support"
	help
	  This option enables the URI parser library based on source from nodejs.
	  This parser requires some string-related routines commonly
	  provided by a libc implementation.

config HTTP_PARSER_STRICT
	bool "HTTP strict parsing"
	depends on (HTTP_PARSER || HTTP_PARSER_URL)
	help
	  This option enables the strict parsing option

config HTTP_CLIENT
	bool "HTTP client API"
	select HTTP_PARSER
	select HTTP_PARSER_URL
	help
	  HTTP client API

menuconfig HTTP_SERVER
	bool "HTTP Server [EXPERIMENTAL]"
	select HTTP_PARSER
	select HTTP_PARSER_URL
	select EXPERIMENTAL
	select NET_SOCKETS
	select ZVFS
	select ZVFS_EVENTFD
	imply NET_IPV4_MAPPING_TO_IPV6 if NET_IPV4 && NET_IPV6
	help
	  HTTP1 and HTTP2 server support.

if HTTP_SERVER

config HTTP_SERVER_STACK_SIZE
	int "HTTP server thread stack size"
	default 4096 if FILE_SYSTEM
	default 3072
	help
	  HTTP server thread stack size for processing RX/TX events.

config HTTP_SERVER_NUM_SERVICES
	int "Number of HTTP Server Instances"
	default 1
	range 1 100
	help
	  This setting determines the number of http services that the server supports.

config HTTP_SERVER_MAX_CLIENTS
	int "Max number of HTTP/2 clients"
	default 3
	range 1 100
	help
	  This setting determines the maximum number of HTTP/2 clients that the server can handle at once.

config HTTP_SERVER_MAX_STREAMS
	int "Max number of HTTP/2 streams"
	default 10
	range 1 100
	help
	  This setting determines the maximum number of HTTP/2 streams for each client.

config HTTP_SERVER_CLIENT_BUFFER_SIZE
	int "Client Buffer Size"
	default 256
	range 64 $(UINT32_MAX)
	help
	  This setting determines the buffer size for each client.

config HTTP_SERVER_HUFFMAN_DECODE_BUFFER_SIZE
	int "Size of the buffer used for decoding Huffman-encoded strings"
	default 256
	range 64 $(UINT32_MAX)
	help
	  Size of the buffer used for decoding Huffman-encoded strings when
	  processing HPACK compressed headers. This effectively limits the
	  maximum length of an individual HTTP header supported.

config HTTP_SERVER_MAX_URL_LENGTH
	int "Maximum HTTP URL Length"
	default 256
	range 32 2048
	help
	  This setting determines the maximum length of the HTTP URL that the server can process.

config HTTP_SERVER_MAX_CONTENT_TYPE_LENGTH
	int "Maximum HTTP Content-Type Length"
	default 64
	range 1 128
	help
	  This setting determines the maximum length of the HTTP Content-Length field.

config HTTP_SERVER_MAX_HEADER_LEN
	int "Maximum HTTP Header Field/Value Length"
	default 32
	range 32 512
	help
	  This setting determines the maximum length of HTTP header field or value
	  that can be parsed. The default value is sufficient for HTTP server
	  internal header processing, and only needs to be increased if the
	  application wishes to access headers of a greater length.

config HTTP_SERVER_HTTP2_MAX_HEADER_FRAME_LEN
	int "Maximum HTTP/2 response header frame length"
	default 64
	range 64 2048
	help
	  This setting determines the maximum length of an HTTP/2 header frame
	  (applies to response headers only, not request headers). The default
	  value is sufficient for the standard headers included with a response,
	  and only needs to be increased if the application wishes to send
	  additional response headers.

config HTTP_SERVER_CAPTURE_HEADERS
	bool "Allow capturing HTTP headers for application use"
	help
	  This setting enables the HTTP server to capture selected headers that have
	  been registered by the application.

config HTTP_SERVER_CAPTURE_HEADER_BUFFER_SIZE
	int "Size of buffer for capturing HTTP headers for application use"
	default 128
	range 32 2048
	depends on HTTP_SERVER_CAPTURE_HEADERS
	help
	  This setting determines the size of the (per-client) buffer used to store
	  HTTP headers for later use by the application.

config HTTP_SERVER_CAPTURE_HEADER_COUNT
	int "Maximum number of HTTP headers to be captured for application use"
	default 3
	range 1 100
	depends on HTTP_SERVER_CAPTURE_HEADERS
	help
	  This setting determines the maximum number of HTTP headers it is possible
	  to capture for application use in a single HTTP request.

config HTTP_SERVER_CLIENT_INACTIVITY_TIMEOUT
	int "Client inactivity timeout (seconds)"
	default 10
	range 1 86400
	help
	  This timeout specifies maximum time the client may remain inactive
	  (i. e. not sending or receiving any data) before the server drops the
	  connection.

config HTTP_SERVER_WEBSOCKET
	bool "Allow upgrading to Websocket connection"
	select WEBSOCKET_CLIENT
	select WEBSOCKET
	help
	  If this is enabled, then the user can allow the HTTP connection to be
	  upgraded to a Websocket connection. The user can then define a Websocket
	  handler that is called after upgrading to handle the Websocket network
	  traffic.

config HTTP_SERVER_RESOURCE_WILDCARD
	bool "Allow wildcard matching of resources"
	# The POSIX_C_LIB_EXT will get fnmatch() support
	select POSIX_C_LIB_EXT
	help
	  Allow user to specify wildcards when setting up resource strings.
	  This means that instead of specifying multiple resources with exact
	  string matches, one resource handler could handle multiple URLs.

config HTTP_SERVER_RESTART_DELAY
	int "Delay before re-initialization when restarting server"
	default 1000
	range 1 60000
	help
	  In case server restarts for any reason, the server re-initialization
	  will be delayed by this value (milliseconds). The delay is needed to
	  allow any existing connections to finalize to avoid binding errors
	  during initialization.

config HTTP_SERVER_TLS_USE_ALPN
	bool "ALPN support for HTTPS server"
	depends on NET_SOCKETS_SOCKOPT_TLS
	depends on MBEDTLS_SSL_ALPN
	help
	  Use ALPN (application layer protocol negotiation) to negotiate HTTP2
	  protocol for TLS connections. Web browsers use this mechanism to determine
	  whether HTTP2 is supported.

config HTTP_SERVER_REPORT_FAILURE_REASON
	bool "Report failure reason in HTTP 500 Internal Server Error reply"
	help
	  If enabled, the server will include the failure reason within
	  HTTP 500 Internal Server Error response. Otherwise, no information
	  is provided within the message.

config WEBSOCKET_CONSOLE
	bool
	default y if HTTP_SERVER_WEBSOCKET && SHELL_BACKEND_WEBSOCKET
	help
	  Hidden option that is enabled only when all the necessary options
	  needed by websocket console are set.

config HTTP_SERVER_COMPRESSION
	bool "Compression support in HTTP fileserver"
	help
	  If enabled, the fileserver will parse the accept-encoding header
	  from the client and extract the supported compression methods.
	  Afterwards it will try to serve the first compressed file available
	  by using the file ending as compression indicator in this order:
	    1. brotli   -> .br
	    2. gzip     -> .gz
	    3. zstd     -> .zst
	    4. compress -> .lzw
	    5. deflate  -> .zz
	    6. File without compression

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

config HTTP_SERVER_COMPLETE_STATUS_PHRASES
	bool "Complete HTTP status reason phrases"
	help
	  Include reason phrases for HTTP status codes in server responses.
	  When disabled, HTTP responses will not include reason phrases,
	  reducing code size. Note that reason phrases are optional per
	  HTTP specification and their absence does not affect protocol
	  compliance or client behavior.

endif

# Hidden option to avoid having multiple individual options that are ORed together
config HTTP
	bool
	depends on (HTTP_PARSER_URL || HTTP_PARSER || HTTP_CLIENT || HTTP_SERVER)
	default y

module = NET_HTTP
module-dep = NET_LOG
module-str = Log level for HTTP client library
module-help = Enables HTTP client code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

module = NET_HTTP_SERVER
module-dep = NET_LOG
module-str = Log level for HTTP server library
module-help = Enables HTTP server code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"
