File syn_http.h¶
FileList > net > syn_http.h
Go to the source code of this file
Cooperative HTTP/1.1 client — streaming, zero-alloc, non-blocking. More...
#include "../common/syn_defs.h"#include "../port/syn_port_socket.h"#include "../pt/syn_pt.h"#include "../sched/syn_task.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_HttpClient HTTP client context structure. |
| struct | SYN_HttpHeader Key-value pair representing an HTTP header. |
| struct | SYN_HttpResponse HTTP response metadata. |
Public Types¶
| Type | Name |
|---|---|
| typedef bool(* | SYN_HttpBodyCallback Callback invoked to stream chunks of the HTTP response body. |
| enum | SYN_HttpState States for the HTTP client cooperative state machine. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_http_client_init (SYN_HttpClient * client, const char * method, const char * host, uint16_t port, const char * path, const char * content_type, const uint8_t * body, size_t body_len, const SYN_HttpHeader * headers, uint8_t header_count, SYN_HttpBodyCallback body_cb, void * cb_ctx, uint8_t * work_buf, size_t work_buf_size) Initialize the HTTP client struct. |
| SYN_PT_Status | syn_http_client_task (SYN_PT * pt, SYN_Task * task) Cooperative task to drive the HTTP client. |
Detailed Description¶
Performs HTTP GET and POST requests over a TCP socket as a cooperative protothread task. Response bodies are delivered via streaming callback.
Public Types Documentation¶
typedef SYN_HttpBodyCallback¶
Callback invoked to stream chunks of the HTTP response body.
Parameters:
dataPointer to the received chunk of body data.lenLength of the data chunk in bytes.ctxUser-defined context pointer passed to syn_http_client_init().
Returns:
true to continue reading body, false to abort.
enum SYN_HttpState¶
States for the HTTP client cooperative state machine.
enum SYN_HttpState {
SYN_HTTP_STATE_IDLE,
SYN_HTTP_STATE_CONNECTING,
SYN_HTTP_STATE_SENDING_REQUEST,
SYN_HTTP_STATE_READING_HEADERS,
SYN_HTTP_STATE_READING_BODY,
SYN_HTTP_STATE_DONE,
SYN_HTTP_STATE_ERROR
};
Public Functions Documentation¶
function syn_http_client_init¶
Initialize the HTTP client struct.
SYN_Status syn_http_client_init (
SYN_HttpClient * client,
const char * method,
const char * host,
uint16_t port,
const char * path,
const char * content_type,
const uint8_t * body,
size_t body_len,
const SYN_HttpHeader * headers,
uint8_t header_count,
SYN_HttpBodyCallback body_cb,
void * cb_ctx,
uint8_t * work_buf,
size_t work_buf_size
)
Configures the request metadata, target destination, custom headers, streaming callback, and temporary work buffer.
Parameters:
clientPointer to the client context to initialize.methodHTTP method to perform (e.g. "GET" or "POST").hostDestination hostname or IP address string.portDestination TCP port (e.g. 80).pathResource URL path (e.g. "/api/v1/update").content_typeType of content if body is present (e.g. "application/json").bodyPointer to binary data to transmit as request body (or NULL).body_lenLength of the request body in bytes.headersOptional array of custom HTTP headers to append.header_countNumber of custom headers in the array.body_cbCallback function for streaming response chunks.cb_ctxUser context passed through to the body callback.work_bufWorking buffer for socket buffering and parsing.work_buf_sizeSize of the working buffer in bytes.
Returns:
SYN_OK on success, or an error code on invalid parameters.
function syn_http_client_task¶
Cooperative task to drive the HTTP client.
Yields while resolving, connecting, transmitting requests, and streaming the response body chunks. Must be run inside the cooperative scheduler.
Parameters:
ptPointer to the cooperative protothread structure.taskPointer to the corresponding task control block.
Returns:
PT_WAITING, PT_EXITED, or another protothread status code.
The documentation for this class was generated from the following file src/syntropic/net/syn_http.h