HTTP Server#
This module contains the HTTP Server API functions.
Functions#
HTTP server initialization function.
Deinitializes the HTTP server and frees all associated resources.
Starts the HTTP server to accept incoming requests.
Stops the HTTP server and waits for all ongoing requests to complete.
Retrieves the headers from an HTTP request.
Reads the HTTP request data being received after the headers.
Sends the HTTP response for the current request.
Sends a chunk of data as part of the HTTP response.
Function Documentation#
sl_http_server_init#
sl_status_t sl_http_server_init (sl_http_server_t * handle, const sl_http_server_config_t * config)
HTTP server initialization function.
[out] | handle | Pointer to an sl_http_server_t object that will be initialized with the server handle. Must not be NULL. |
[in] | config | Pointer to the HTTP server configuration structure of type sl_http_server_config_t. Must not be NULL. |
This function initializes an HTTP server using the provided configuration structure and returns a handle to the server. It sets up the server's configuration, request buffer, and event flags. All subsequent HTTP server APIs must be used with the server handle returned in the handle
parameter.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: Invalid input parameter.
54
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_deinit#
sl_status_t sl_http_server_deinit (sl_http_server_t * handle)
Deinitializes the HTTP server and frees all associated resources.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
This function deinitializes the HTTP server, releasing all resources associated with the provided HTTP server handle. It closes the server socket, deletes event flags, and resets the request handlers. After calling this function, the handle
parameter should not be used in any other API without reinitializing it using sl_http_server_init.
The HTTP server handle should be initialized using sl_http_server_init before calling this function.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: Invalid input parameter.
Note
After calling this function, the
handle
parameter should not be used in any other API without calling sl_http_server_init again.
79
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_start#
sl_status_t sl_http_server_start (sl_http_server_t * handle)
Starts the HTTP server to accept incoming requests.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
This function spawns a new thread dedicated to accept the incoming HTTP requests on the configured HTTP port. The HTTP request handlers are invoked from this thread to process the requests. It ensures that the server is ready to handle client connections.
The HTTP server handle should be initialized using sl_http_server_init before calling this function.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: The provided handle is NULL.
SL_STATUS_FAIL: Failed to create the server thread.
101
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_stop#
sl_status_t sl_http_server_stop (sl_http_server_t * handle)
Stops the HTTP server and waits for all ongoing requests to complete.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
This function sends a stop command to the HTTP server thread, and waits for all ongoing requests to complete. It ensures that the server thread is properly terminated, and all resources associated with the server thread are released.
The HTTP server handle should be initialized using sl_http_server_init before calling this function.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_FAIL: Failed to stop the server thread.
122
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_get_request_headers#
sl_status_t sl_http_server_get_request_headers (sl_http_server_t * handle, sl_http_server_request_t * request, sl_http_header_t * headers, uint16_t header_count)
Retrieves the headers from an HTTP request.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
[in] | request | Pointer to an sl_http_server_request_t object representing the HTTP request from which headers are to be retrieved. Must not be NULL. |
[out] | headers | Pointer to an array of sl_http_header_t where the retrieved headers would be stored. Must not be NULL. |
[in] | header_count | The number of headers that the |
This function extracts all headers from a given HTTP request, and stores them in the provided headers array. It parses the HTTP request to identify and extract the headers, which are then stored in the array pointed to by the headers
parameter.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: One or more input parameters are NULL or invalid.
SL_STATUS_FAIL: Failed to retrieve headers from the HTTP request.
150
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_read_request_data#
sl_status_t sl_http_server_read_request_data (sl_http_server_t * handle, sl_http_recv_req_data_t * data)
Reads the HTTP request data being received after the headers.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
[in] | data | Pointer to an sl_http_recv_req_data_t structure where the received request data would be stored. Must not be NULL. |
This function reads the data portion of an HTTP request that follows the headers. It is used to process the body of the request.
The
req_data_length
parameter in sl_http_server_request_t must be greater than 0.This function must be called from within the request handler of the corresponding request.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: One or more input parameters are NULL or invalid.
SL_STATUS_FAIL: Failed to read the request data.
178
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_send_response#
sl_status_t sl_http_server_send_response (sl_http_server_t * handle, sl_http_server_response_t * response)
Sends the HTTP response for the current request.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
[in] | response | Pointer to an sl_http_server_response_t object representing the response to be sent. Must not be NULL. |
This function makes the HTTP server send the response to the current request. It can only be called once per request.
The HTTP server handle should be initialized using sl_http_server_init before calling this function.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: One or more input parameters are NULL or invalid.
SL_STATUS_FAIL: Failed to send the response.
202
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_write_data#
sl_status_t sl_http_server_write_data (sl_http_server_t * handle, uint8_t * data, uint32_t data_length)
Sends a chunk of data as part of the HTTP response.
[in] | handle | Pointer to an sl_http_server_t object representing the HTTP server handle. Must not be NULL. |
[in] | data | Pointer to the data to be sent. Must not be NULL. |
[in] | data_length | Length of the data to be sent. |
This function sends a chunk of data as part of the HTTP response. It should be used after a response has been started with sl_http_server_send_response, and can be called multiple times to send the response data in chunks.
The HTTP response must be initiated using sl_http_server_send_response before calling this function.
Returns
sl_status_t - Status of the operation. For more details, see https://docs.silabs.com/gecko-platform/latest/platform-common/status.
SL_STATUS_OK: Operation successful.
SL_STATUS_INVALID_PARAMETER: One or more input parameters are NULL or invalid.
SL_STATUS_FAIL: Failed to send the data chunk.
230
of file components/service/sl_http_server/inc/sl_http_server.h