A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
fetch.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
35#ifndef A11_NET_HTTP_FETCH_H_
36#define A11_NET_HTTP_FETCH_H_
37
38#include <cstdint>
39#include <functional>
40#include <string>
41#include <string_view>
42
43#include <absl/status/status.h>
44#include <absl/time/time.h>
45
47#include "a11/net/http2.h"
48
49namespace a11::net {
50
58 std::function<void(std::uint64_t bytes_done, std::uint64_t bytes_total)>;
59
66using FetchSink = std::function<absl::Status(std::string_view chunk)>;
67
70 std::string method = "GET";
72 std::string body;
80 absl::Duration timeout = absl::Minutes(5);
89 bool default_user_agent = true;
90
92 absl::Status Validate() const;
93};
94
105a11::Future<HttpResponse> Fetch(std::string url, FetchOptions options = {});
106
122 FetchOptions options = {},
123 OnFetchProgress on_progress = {});
124
125namespace internal {
126
136absl::StatusOr<HttpResponseHead> FetchBlocking(
137 std::string url, FetchOptions options, const FetchSink& sink,
138 const OnFetchProgress& on_progress = {});
139
140} // namespace internal
141
142} // namespace a11::net
143
144#endif // A11_NET_HTTP_FETCH_H_
Shared handle to one asynchronous result.
Definition future.h:126
Completion values used by every asynchronous A11 operation.
A11's nghttp2 HTTP/2 client, server, and streaming primitives.
absl::StatusOr< HttpResponseHead > 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.
Definition fetch.cc:238
Definition action.h:65
a11::Future< HttpResponseHead > FetchToSink(std::string url, FetchSink sink, FetchOptions options, OnFetchProgress on_progress)
Fetches url and hands the body to sink as it arrives.
Definition fetch.cc:277
std::vector< std::pair< std::string, std::string > > HttpHeaders
An ordered list of (name, value) HTTP/2 header fields.
Definition http2.h:70
std::function< void(std::uint64_t bytes_done, std::uint64_t bytes_total)> OnFetchProgress
Called as a body arrives.
Definition fetch.h:58
std::function< absl::Status(std::string_view chunk)> FetchSink
Receives body chunks in order.
Definition fetch.h:66
a11::Future< HttpResponse > Fetch(std::string url, FetchOptions options)
Fetches url and buffers the whole response.
Definition fetch.cc:252
What to request, and how hard to try.
Definition fetch.h:69
absl::Duration timeout
Wall-clock bound on the whole operation, redirects included.
Definition fetch.h:80
std::string method
Request method.
Definition fetch.h:70
absl::Status Validate() const
Definition fetch.cc:222
int max_redirects
Redirects to follow before giving up.
Definition fetch.h:78
Http2Options transport
Transport settings.
Definition fetch.h:87
HttpHeaders headers
Extra request headers.
Definition fetch.h:71
std::string body
Request body, for methods that take one.
Definition fetch.h:72
bool default_user_agent
Send a default user-agent when headers does not carry one.
Definition fetch.h:89
Body-size limits, buffering thresholds, deadline, TLS, and HTTP protocol negotiation for an HTTP clie...
Definition http2.h:150