Type Alias esp_idf_svc::sys::httpd_config_t

source ·
pub type httpd_config_t = httpd_config;
Expand description

@brief HTTP Server Configuration Structure

@note Use HTTPD_DEFAULT_CONFIG() to initialize the configuration to a default value and then modify only those fields that are specifically determined by the use case.

Aliased Type§

struct httpd_config_t {
Show 25 fields pub task_priority: u32, pub stack_size: usize, pub core_id: i32, pub server_port: u16, pub ctrl_port: u16, pub max_open_sockets: u16, pub max_uri_handlers: u16, pub max_resp_headers: u16, pub backlog_conn: u16, pub lru_purge_enable: bool, pub recv_wait_timeout: u16, pub send_wait_timeout: u16, pub global_user_ctx: *mut c_void, pub global_user_ctx_free_fn: Option<unsafe extern "C" fn(_: *mut c_void)>, pub global_transport_ctx: *mut c_void, pub global_transport_ctx_free_fn: Option<unsafe extern "C" fn(_: *mut c_void)>, pub enable_so_linger: bool, pub linger_timeout: i32, pub keep_alive_enable: bool, pub keep_alive_idle: i32, pub keep_alive_interval: i32, pub keep_alive_count: i32, pub open_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: i32) -> i32>, pub close_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: i32)>, pub uri_match_fn: Option<unsafe extern "C" fn(_: *const i8, _: *const i8, _: usize) -> bool>,
}

Fields§

§task_priority: u32

< Priority of FreeRTOS task which runs the server

§stack_size: usize

< The maximum stack size allowed for the server task

§core_id: i32

< The core the HTTP server task will run on

§server_port: u16

TCP Port number for receiving and transmitting HTTP traffic

§ctrl_port: u16

UDP Port number for asynchronously exchanging control signals between various components of the server

§max_open_sockets: u16

< Max number of sockets/clients connected at any time (3 sockets are reserved for internal working of the HTTP server)

§max_uri_handlers: u16

< Maximum allowed uri handlers

§max_resp_headers: u16

< Maximum allowed additional headers in HTTP response

§backlog_conn: u16

< Number of backlog connections

§lru_purge_enable: bool

< Purge “Least Recently Used” connection

§recv_wait_timeout: u16

< Timeout for recv function (in seconds)

§send_wait_timeout: u16

< Timeout for send function (in seconds)

§global_user_ctx: *mut c_void

Global user context.

This field can be used to store arbitrary user data within the server context. The value can be retrieved using the server handle, available e.g. in the httpd_req_t struct.

When shutting down, the server frees up the user context by calling free() on the global_user_ctx field. If you wish to use a custom function for freeing the global user context, please specify that here.

§global_user_ctx_free_fn: Option<unsafe extern "C" fn(_: *mut c_void)>

Free function for global user context

§global_transport_ctx: *mut c_void

Global transport context.

Similar to global_user_ctx, but used for session encoding or encryption (e.g. to hold the SSL context). It will be freed using free(), unless global_transport_ctx_free_fn is specified.

§global_transport_ctx_free_fn: Option<unsafe extern "C" fn(_: *mut c_void)>

Free function for global transport context

§enable_so_linger: bool

< bool to enable/disable linger

§linger_timeout: i32

< linger timeout (in seconds)

§keep_alive_enable: bool

< Enable keep-alive timeout

§keep_alive_idle: i32

< Keep-alive idle time. Default is 5 (second)

§keep_alive_interval: i32

< Keep-alive interval time. Default is 5 (second)

§keep_alive_count: i32

< Keep-alive packet retry send count. Default is 3 counts

§open_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: i32) -> i32>

Custom session opening callback.

Called on a new session socket just after accept(), but before reading any data.

This is an opportunity to set up e.g. SSL encryption using global_transport_ctx and the send/recv/pending session overrides.

If a context needs to be maintained between these functions, store it in the session using httpd_sess_set_transport_ctx() and retrieve it later with httpd_sess_get_transport_ctx()

Returning a value other than ESP_OK will immediately close the new socket.

§close_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: i32)>

Custom session closing callback.

Called when a session is deleted, before freeing user and transport contexts and before closing the socket. This is a place for custom de-init code common to all sockets.

The server will only close the socket if no custom session closing callback is set. If a custom callback is used, close(sockfd) should be called in here for most cases.

Set the user or transport context to NULL if it was freed here, so the server does not try to free it again.

This function is run for all terminated sessions, including sessions where the socket was closed by the network stack - that is, the file descriptor may not be valid anymore.

§uri_match_fn: Option<unsafe extern "C" fn(_: *const i8, _: *const i8, _: usize) -> bool>

URI matcher function.

Called when searching for a matching URI: 1) whose request handler is to be executed right after an HTTP request is successfully parsed 2) in order to prevent duplication while registering a new URI handler using httpd_register_uri_handler()

Available options are: 1) NULL : Internally do basic matching using strncmp() 2) httpd_uri_match_wildcard() : URI wildcard matcher

Users can implement their own matching functions (See description of the httpd_uri_match_func_t function prototype)