NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
http_client.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <neograph/api.h>
17
18#include <asio/awaitable.hpp>
19#include <asio/any_io_executor.hpp>
20
21#include <chrono>
22#include <cstddef>
23#include <functional>
24#include <string>
25#include <string_view>
26#include <utility>
27#include <vector>
28
29namespace neograph::async {
30
31struct NEOGRAPH_API HttpResponse {
32 int status = 0;
33 std::string body;
34
39 std::string retry_after;
40
45 std::string location;
46
57 std::vector<std::pair<std::string, std::string>> headers;
58
62 std::string_view get_header(std::string_view name) const noexcept;
63};
64
72 std::chrono::milliseconds timeout{0};
73
85 std::chrono::milliseconds connect_timeout{0};
86
92 bool allow_replay = false;
93
100
103 std::size_t max_response_header_bytes = 64 * 1024;
104
108 std::size_t max_response_body_bytes = 16 * 1024 * 1024;
109
112 std::size_t max_response_chunk_bytes = 1024 * 1024;
113};
114
136NEOGRAPH_API asio::awaitable<HttpResponse> async_post(
137 asio::any_io_executor ex,
138 std::string_view host,
139 std::string_view port,
140 std::string_view path,
141 std::string_view body,
142 std::vector<std::pair<std::string, std::string>> headers = {},
143 bool tls = false,
144 RequestOptions opts = {});
145
151NEOGRAPH_API asio::awaitable<HttpResponse> async_get(
152 asio::any_io_executor ex,
153 std::string_view host,
154 std::string_view port,
155 std::string_view path,
156 std::vector<std::pair<std::string, std::string>> headers = {},
157 bool tls = false,
158 RequestOptions opts = {});
159
164 int status = 0;
165};
166
186NEOGRAPH_API asio::awaitable<HttpStreamResponse> async_post_stream(
187 asio::any_io_executor ex,
188 std::string_view host,
189 std::string_view port,
190 std::string_view path,
191 std::string_view body,
192 std::vector<std::pair<std::string, std::string>> headers,
193 bool tls,
194 std::function<void(std::string_view chunk)> on_chunk,
195 RequestOptions opts = {});
196
198struct NEOGRAPH_API HttpResponseHead {
199 int status = 0;
201 std::vector<std::pair<std::string, std::string>> headers;
202
204 std::string_view get_header(std::string_view name) const noexcept;
205};
206
216NEOGRAPH_API asio::awaitable<HttpStreamResponse> async_request_stream(
217 asio::any_io_executor ex,
218 std::string_view method,
219 std::string_view host,
220 std::string_view port,
221 std::string_view target,
222 std::string_view body,
223 std::vector<std::pair<std::string, std::string>> headers,
224 bool tls,
225 std::function<void(const HttpResponseHead&)> on_head,
226 std::function<void(std::string_view chunk)> on_chunk,
227 RequestOptions opts = {});
228
229} // namespace neograph::async
NEOGRAPH_API export/import macro for shared-library builds.
NEOGRAPH_API asio::awaitable< HttpStreamResponse > 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 with chunked, bounded Content-Length, or close-delimited response bodies.
NEOGRAPH_API asio::awaitable< HttpResponse > 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< HttpResponse > 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< HttpStreamResponse > async_request_stream(asio::any_io_executor ex, std::string_view method, std::string_view host, std::string_view port, std::string_view target, std::string_view body, std::vector< std::pair< std::string, std::string > > headers, bool tls, std::function< void(const HttpResponseHead &)> on_head, std::function< void(std::string_view chunk)> on_chunk, RequestOptions opts={})
Async HTTP(S) request of any method (POST, GET, DELETE, ...) with a streamed response.
Status and headers of a streamed response, reported before its body.
std::vector< std::pair< std::string, std::string > > headers
Every response header, in wire order.
std::string_view get_header(std::string_view name) const noexcept
Case-insensitive header lookup; empty when the header is absent.
Metadata returned by async_post_stream after the body has been fully delivered via the callback.
std::chrono::milliseconds timeout
Per-hop deadline covering connect + handshake + write + read of one HTTP exchange.
Definition http_client.h:72
bool allow_replay
For ConnPool, permit one replay after a stale keep-alive connection fails.
Definition http_client.h:92
std::size_t max_response_chunk_bytes
Maximum bytes accepted in one HTTP transfer chunk (or one Curl body callback).
std::chrono::milliseconds connect_timeout
Deadline for establishing the connection only: name resolution, the TCP connect and,...
Definition http_client.h:85
std::size_t max_response_header_bytes
Maximum bytes accepted for a response status/header block, trailer block, or individual chunk-size li...
std::size_t max_response_body_bytes
Maximum decoded response body bytes accepted per hop.
int max_redirects
Max 3xx hops to follow automatically.
Definition http_client.h:99