Artifact 91367c7127500490aa81ffb11c10fbeaa9f55c8a9e2b58903c504a6e4bcfa68c:
- File
src/http.h
— part of check-in
[7ce5fcd871]
at
2026-11-18 17:26:22
on branch stage-2
— Add an HTTPS stack on vendored BearSSL
BearSSL 0.6 is vendored and verified byte for byte against the upstream release. net.c adapts suit TLS and trust-anchor code to C11 with a deadline-bounded name lookup and TCP connect; http.c is a strict HTTP/1.1 response parser and one-shot POST. A probe completes a TLS 1.2 handshake and an HTTP exchange with the Messages API and refuses expired, wrong-host, self-signed and plain-HTTP endpoints. (user: dmestas, size: 2114) [annotate] [blame] [check-ins using] [more...]
/* HTTP/1.1 for one POST per connection. The response parser is a pure * function over bytes (status line, headers, then a body delimited by chunked * encoding, Content-Length or the end of the connection), so it is fuzzed on * its own. */ #ifndef PIC_HTTP_H #define PIC_HTTP_H #include <stddef.h> #include "net.h" /* Body bytes as they arrive. Nonzero stops the response; feed returns it. */ typedef int (*pic_http_body_fn)(void *ctx, const char *bytes, size_t n); typedef struct { int state; /* internal */ int status; /* final status code, once headers are done */ char retry_after[32]; /* Retry-After value, if any */ char request_id[128]; /* request-id header, if any */ char content_type[128]; /* Content-Type, if any */ pic_http_body_fn on_body; void *ctx; char line[8192]; size_t line_len; size_t header_bytes; unsigned long long remaining; /* bytes left of the body or chunk */ int chunked, has_length, body_started; char err[160]; } pic_http_resp; void pic_http_resp_init(pic_http_resp *r, pic_http_body_fn on_body, void *ctx); /* 0, a callback's nonzero value, or -1 on a malformed response (r->err). */ int pic_http_feed(pic_http_resp *r, const char *bytes, size_t n); /* 1 once the body is complete (more bytes are an error). */ int pic_http_done(const pic_http_resp *r); /* At the end of the connection: 0 if the response was complete, else -1. */ int pic_http_end(pic_http_resp *r); /* POSTs body to url (https://host[:port]/path, or http:// to loopback only) * with extra header lines ("Name: value"), streaming the response body to * r's callback. Header values are never copied into errors. 0 when a full * response arrived (any status), -1 on a transport or protocol failure with * err set. pic_net_tls_failed(net) then tells a TLS failure from others. */ int pic_http_post(pic_net *net, const char *url, const char *const *headers, size_t nheaders, const char *body, size_t body_len, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); #endif