|
NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
|
Minimal async HTTP/1.1 POST client on asio coroutines. More...
#include <neograph/api.h>#include <asio/awaitable.hpp>#include <asio/any_io_executor.hpp>#include <chrono>#include <functional>#include <string>#include <string_view>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | neograph::async::HttpStreamResponse |
| Metadata returned by async_post_stream after the body has been fully delivered via the callback. More... | |
| struct | neograph::async::RequestOptions |
| Per-call knobs. More... | |
Functions | |
| NEOGRAPH_API asio::awaitable< HttpResponse > | neograph::async::async_get (asio::any_io_executor ex, std::string_view host, std::string_view port, std::string_view path, std::vector< std::pair< std::string, std::string > > headers={}, bool tls=false, RequestOptions opts={}) |
| Async HTTP(S) GET. | |
| NEOGRAPH_API asio::awaitable< HttpResponse > | neograph::async::async_post (asio::any_io_executor ex, std::string_view host, std::string_view port, std::string_view path, std::string_view body, std::vector< std::pair< std::string, std::string > > headers={}, bool tls=false, RequestOptions opts={}) |
| Async HTTP(S) POST. | |
| NEOGRAPH_API asio::awaitable< HttpStreamResponse > | neograph::async::async_post_stream (asio::any_io_executor ex, std::string_view host, std::string_view port, std::string_view path, std::string_view body, std::vector< std::pair< std::string, std::string > > headers, bool tls, std::function< void(std::string_view chunk)> on_chunk, RequestOptions opts={}) |
| Async HTTP(S) POST where the server emits a Transfer-Encoding: chunked response body. | |
Minimal async HTTP/1.1 POST client on asio coroutines.
Stage 3 / Semester 1.1 — adds TLS via asio::ssl::stream. Still HTTP/1.1 only with no chunked transfer, keep-alive, redirects, or auth helpers; the TLS path is what makes real LLM endpoints reachable. Keep-alive, SSE, redirects land in 1.2–1.5.
Every call opens a fresh connect → (handshake) → write → read → close cycle. The TLS branch verifies the peer certificate against OpenSSL's default trust store and sets SNI to the requested host.
Definition in file http_client.h.
| NEOGRAPH_API asio::awaitable< HttpResponse > neograph::async::async_get | ( | asio::any_io_executor | ex, |
| std::string_view | host, | ||
| std::string_view | port, | ||
| std::string_view | path, | ||
| std::vector< std::pair< std::string, std::string > > | headers = {}, |
||
| bool | tls = false, |
||
| RequestOptions | opts = {} |
||
| ) |
Async HTTP(S) GET.
Same shape as async_post but issues a GET request with an empty body and no Content-Length / Content-Type headers — used for resources like the A2A /.well-known/agent-card.json discovery endpoint.
References neograph::async::async_get().
Referenced by neograph::async::async_get().
| NEOGRAPH_API asio::awaitable< HttpResponse > neograph::async::async_post | ( | asio::any_io_executor | ex, |
| std::string_view | host, | ||
| std::string_view | port, | ||
| std::string_view | path, | ||
| std::string_view | body, | ||
| std::vector< std::pair< std::string, std::string > > | headers = {}, |
||
| bool | tls = false, |
||
| RequestOptions | opts = {} |
||
| ) |
Async HTTP(S) POST.
Returns the response body and status on the given executor's thread(s). Throws asio::system_error (or std::system_error wrapping SSL errors) on transport failure — caller decides retry policy.
| ex | Executor (io_context / strand) where the coroutine runs. |
| host | Target host (e.g. "127.0.0.1" or "api.anthropic.com"). When tls is true this is also used as the SNI value and the name verified against the peer certificate. |
| port | Port string (e.g. "8080", "443"). Resolver-compatible. |
| path | Path with leading slash (e.g. "/v1/messages"). |
| body | Raw request body. Content-Length is computed from it. |
| headers | Optional extra headers (name, value) pairs. Callers typically set "Authorization", "Content-Type", "x-api-key" etc. |
| tls | When true, wrap the socket in asio::ssl::stream, do TLS handshake with SNI=host, and verify the peer certificate against the system trust store. |
References neograph::async::async_post().
Referenced by neograph::async::async_post().
| NEOGRAPH_API asio::awaitable< HttpStreamResponse > neograph::async::async_post_stream | ( | asio::any_io_executor | ex, |
| std::string_view | host, | ||
| std::string_view | port, | ||
| std::string_view | path, | ||
| std::string_view | body, | ||
| std::vector< std::pair< std::string, std::string > > | headers, | ||
| bool | tls, | ||
| std::function< void(std::string_view chunk)> | on_chunk, | ||
| RequestOptions | opts = {} |
||
| ) |
Async HTTP(S) POST where the server emits a Transfer-Encoding: chunked response body.
Each chunk is delivered to on_chunk in wire order; the returned HttpStreamResponse carries only the status line. Used for LLM streaming endpoints (OpenAI chat completions, Anthropic messages in stream: true mode).
Throws asio::system_error on transport failure or std::runtime_error if the response isn't chunked. HTTP-level errors (4xx, 5xx) surface as status + their usually-small body delivered to on_chunk — the caller decides what to do.
The request uses Connection: close — chunked streams are typically long-lived and sharing a conn afterwards offers little amortization. ConnPool integration is deferred to a later Semester if/when a streaming workload wants it.
The bytes passed to on_chunk are only valid for the duration of the callback invocation; copy them out if you need to retain.
References neograph::async::async_post_stream().
Referenced by neograph::async::async_post_stream().