Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
HTTP server API

Data Structures

struct  http_resource_detail
 Representation of a server resource, common for all resource types. More...
 
struct  http_resource_detail_static
 Representation of a static server resource. More...
 
struct  http_resource_detail_dynamic
 Representation of a dynamic server resource. More...
 
struct  http_resource_detail_websocket
 Representation of a websocket server resource. More...
 
struct  http_stream_ctx
 HTTP/2 stream representation. More...
 
struct  http_frame
 HTTP/2 frame representation. More...
 
struct  http_client_ctx
 Representation of an HTTP client connected to the server. More...
 

Typedefs

typedef int(* http_resource_dynamic_cb_t) (struct http_client_ctx *client, enum http_data_status status, uint8_t *data_buffer, size_t data_len, void *user_data)
 Callback used when data is received.
 
typedef int(* http_resource_websocket_cb_t) (int ws_socket, void *user_data)
 Callback used when a Websocket connection is setup.
 

Enumerations

enum  http_resource_type { HTTP_RESOURCE_TYPE_STATIC , HTTP_RESOURCE_TYPE_DYNAMIC , HTTP_RESOURCE_TYPE_WEBSOCKET }
 HTTP server resource type. More...
 
enum  http_data_status { HTTP_SERVER_DATA_ABORTED = -1 , HTTP_SERVER_DATA_MORE = 0 , HTTP_SERVER_DATA_FINAL = 1 }
 Indicates the status of the currently processed piece of data. More...
 

Functions

int http_server_start (void)
 Start the HTTP2 server.
 
int http_server_stop (void)
 Stop the HTTP2 server.
 

Detailed Description

Typedef Documentation

◆ http_resource_dynamic_cb_t

http_resource_dynamic_cb_t

#include <zephyr/net/http/server.h>

Callback used when data is received.

Data to be sent to client can be specified.

Parameters
clientHTTP context information for this client connection.
statusHTTP data status, indicate whether more data is expected or not.
data_bufferData received.
data_lenAmount of data received.
user_dataUser specified data.
Returns
>0 amount of data to be sent to client, let server to call this function again when new data is received. 0 nothing to sent to client, close the connection <0 error, close the connection.

◆ http_resource_websocket_cb_t

http_resource_websocket_cb_t

#include <zephyr/net/http/server.h>

Callback used when a Websocket connection is setup.

The application will need to handle all functionality related to the connection like reading and writing websocket data, and closing the connection.

Parameters
ws_socketA socket for the Websocket data.
user_dataUser specified data.
Returns
0 Accepting the connection, HTTP server library will no longer handle data to/from the socket and it is application responsibility to send and receive data to/from the supplied socket. <0 error, close the connection.

Enumeration Type Documentation

◆ http_data_status

#include <zephyr/net/http/server.h>

Indicates the status of the currently processed piece of data.


Enumerator
HTTP_SERVER_DATA_ABORTED 

Transaction aborted, data incomplete.

HTTP_SERVER_DATA_MORE 

Transaction incomplete, more data expected.

HTTP_SERVER_DATA_FINAL 

Final data fragment in current transaction.

◆ http_resource_type

#include <zephyr/net/http/server.h>

HTTP server resource type.

Enumerator
HTTP_RESOURCE_TYPE_STATIC 

Static resource, cannot be modified on runtime.

HTTP_RESOURCE_TYPE_DYNAMIC 

Dynamic resource, server interacts with the application via registered http_resource_dynamic_cb_t.

HTTP_RESOURCE_TYPE_WEBSOCKET 

Websocket resource, application takes control over Websocket connection after and upgrade.

Function Documentation

◆ http_server_start()

int http_server_start ( void  )

#include <zephyr/net/http/server.h>

Start the HTTP2 server.

The server runs in a background thread. Once started, the server will create a server socket for all HTTP services registered in the system and accept connections from clients (see HTTP_SERVICE_DEFINE).

◆ http_server_stop()

int http_server_stop ( void  )

#include <zephyr/net/http/server.h>

Stop the HTTP2 server.

All server sockets are closed and the server thread is suspended.