A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
fetch.h File Reference

One-shot HTTP requests by URL, with redirects and a streaming sink. More...

#include <cstdint>
#include <functional>
#include <string>
#include <string_view>
#include <absl/status/status.h>
#include <absl/time/time.h>
#include "a11/concurrency/future.h"
#include "a11/net/http2.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  a11::net::FetchOptions
 What to request, and how hard to try. More...
 

Namespaces

namespace  a11
 
namespace  a11::net
 
namespace  a11::net::internal
 

Typedefs

using a11::net::OnFetchProgress = std::function< void(std::uint64_t bytes_done, std::uint64_t bytes_total)>
 Called as a body arrives.
 
using a11::net::FetchSink = std::function< absl::Status(std::string_view chunk)>
 Receives body chunks in order.
 

Functions

a11::Future< HttpResponse > a11::net::Fetch (std::string url, FetchOptions options={})
 Fetches url and buffers the whole response.
 
a11::Future< HttpResponseHead > a11::net::FetchToSink (std::string url, FetchSink sink, FetchOptions options={}, OnFetchProgress on_progress={})
 Fetches url and hands the body to sink as it arrives.
 
absl::StatusOr< HttpResponseHead > a11::net::internal::FetchBlocking (std::string url, FetchOptions options, const FetchSink &sink, const OnFetchProgress &on_progress={})
 The blocking core of FetchToSink, for a caller already on a fiber.
 

Detailed Description

One-shot HTTP requests by URL, with redirects and a streaming sink.

Http2Client already owns the hard parts – TLS, ALPN, HTTP/2 with an HTTP/1.1 fallback, and backpressure – but it is dialled by host and port and its buffered Request() caps a response at Http2Options::max_response_body_size. These helpers add what a caller fetching a URL needs on top: scheme-driven TLS, Location following, and a sink so a body larger than memory (a model file) never has to be one string.

Both entry points return an a11::Future and do their blocking on a pooled fiber via a11::Submit, so neither may be called from the libuv loop thread and neither blocks it. Every failure is an absl::Status; a response status of 400 or more becomes one through a11::StatusCodeFromHttp, with the URL and response code attached as structured details.