calog/libs/calogHttp.h

30 lines
1.7 KiB
C

// calogHttp.h -- calog HTTP client library.
//
// Bridges calog scripts to a minimal HTTP/1.1 client so any engine can fetch and post over
// http:// and https:// without an engine-specific library:
// httpGet(url) -> { status, body, headers }
// httpRequest(opts) -> { status, body, headers }
// where opts is a map { method (default "GET"), url, headers (map of name->value), body,
// insecure (bool), maxRedirects (int) }. The result map carries the integer status code, the
// binary-safe response body, and a headers map keyed by the lowercased header name. Each call
// opens its own connection ("Connection: close"), reads the whole response to EOF, and decodes
// the body honoring Transfer-Encoding: chunked / Content-Length / read-to-close. 3xx redirects
// ARE followed (up to maxRedirects, default 16, capped at 16 to break loops; 0 disables and
// returns the raw 3xx). 303 -- and 301/302 for a body-bearing method -- become a bodyless GET;
// 307/308 keep the method and body. For https:// the TLS handshake uses SNI and, by DEFAULT,
// verifies the server certificate chain against the system CA store and checks it matches the
// requested hostname (an untrusted or mismatched certificate fails the request). Pass
// insecure=true to httpRequest to skip verification (self-signed / development endpoints).
// The natives are INLINE (each call is a self-contained connection with no shared state), so
// there is nothing to shut down.
#ifndef CALOG_HTTP_H
#define CALOG_HTTP_H
#include "calog.h"
// Register the HTTP natives (httpGet, httpRequest) on a runtime. Stateless: safe to call on
// any number of runtimes, and there is no matching shutdown.
int32_t calogHttpRegister(CalogT *calog);
#endif