CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
HTTP (streamed)

Make outbound HTTP/HTTPS requests with streaming response reads. More...

Macros

#define HTTP_GET   0
#define HTTP_POST   1
#define HTTP_PUT   2
#define HTTP_DELETE   3

Functions

int host_http_open (uint8_t method, const char *url, uint32_t timeout_ms)
 Open an HTTP request.
int host_http_set_header (int handle, const char *key, const char *value)
 Add a request header before perform().
int host_http_set_body (int handle, const uint8_t *body, size_t len)
 Stage a request body before perform().
int host_http_perform (int handle)
 Send the request and read response headers.
int host_http_status (int handle)
 HTTP response status code, or negative on error.
int host_http_read_chunk (int handle, uint8_t *buf, size_t buf_size, size_t *out_len)
 Stream one response chunk into buf.
size_t host_http_content_length (int handle)
 Response Content-Length, or 0 when unknown / chunked.
int host_http_close (int handle)
 Release a request handle.

Detailed Description

Make outbound HTTP/HTTPS requests with streaming response reads.

Opens a handle, lets you stage headers/body, performs the request, then streams the response in chunks. Always close the handle when done, even after errors. Requires manifest capability "http".

Macro Definition Documentation

◆ HTTP_DELETE

#define HTTP_DELETE   3

Definition at line 329 of file host_api.h.

◆ HTTP_GET

#define HTTP_GET   0

Definition at line 326 of file host_api.h.

◆ HTTP_POST

#define HTTP_POST   1

Definition at line 327 of file host_api.h.

◆ HTTP_PUT

#define HTTP_PUT   2

Definition at line 328 of file host_api.h.

Function Documentation

◆ host_http_close()

int host_http_close ( int handle)

Release a request handle.

Definition at line 317 of file host_api_http.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_http_close().

◆ host_http_content_length()

size_t host_http_content_length ( int handle)

Response Content-Length, or 0 when unknown / chunked.

Definition at line 311 of file host_api_http.cpp.

Referenced by cdc::plugin_manager::w_host_http_content_length().

◆ host_http_open()

int host_http_open ( uint8_t method,
const char * url,
uint32_t timeout_ms )

Open an HTTP request.

Parameters
methodOne of HTTP_GET/POST/PUT/DELETE.
urlAbsolute URL including scheme.
timeout_msConnect + response timeout.
Returns
Handle > 0 on success, negative HostError on failure.

Definition at line 178 of file host_api_http.cpp.

References cdc::plugin_manager::SlotTable< T, N >::allocate(), HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, makeClient(), and plg_get_active_plugin().

Referenced by cdc::plugin_manager::w_host_http_open().

◆ host_http_perform()

int host_http_perform ( int handle)

Send the request and read response headers.

Definition at line 253 of file host_api_http.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_OK, LOG_E, LOG_I, and LOG_W.

Referenced by cdc::plugin_manager::w_host_http_perform().

◆ host_http_read_chunk()

int host_http_read_chunk ( int handle,
uint8_t * buf,
size_t buf_size,
size_t * out_len )

Stream one response chunk into buf.

Parameters
out_lenBytes actually read; 0 indicates end of response.

Definition at line 299 of file host_api_http.cpp.

References HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_http_read_chunk().

◆ host_http_set_body()

int host_http_set_body ( int handle,
const uint8_t * body,
size_t len )

Stage a request body before perform().

Definition at line 243 of file host_api_http.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_http_set_body().

◆ host_http_set_header()

int host_http_set_header ( int handle,
const char * key,
const char * value )

Add a request header before perform().

Definition at line 235 of file host_api_http.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, and HOST_OK.

Referenced by cdc::plugin_manager::w_host_http_set_header().

◆ host_http_status()

int host_http_status ( int handle)

HTTP response status code, or negative on error.

Definition at line 293 of file host_api_http.cpp.

References HOST_ERR_INVALID_ARG.

Referenced by cdc::plugin_manager::w_host_http_status().