Fastly Compute C++ SDK
Loading...
Searching...
No Matches
response.h
Go to the documentation of this file.
1#ifndef FASTLY_HTTP_RESPONSE_H
2#define FASTLY_HTTP_RESPONSE_H
3
4#include <chrono>
5#include <fastly/backend.h>
7#include <fastly/error.h>
8#include <fastly/http/body.h>
10#include <fastly/http/http.h>
11#include <fastly/http/request.h>
13#include <fastly/sdk-sys.h>
14#include <string>
15#include <string_view>
16#include <utility>
17#include <vector>
18
19namespace fastly::backend {
20class Backend;
21}
22
23namespace fastly::http {
24
25class Body;
26class StreamingBody;
27class Response;
28class Request;
29namespace request {
30class PendingRequest;
31std::pair<fastly::expected<Response>, std::vector<PendingRequest>>
32select(std::vector<PendingRequest> &reqs);
33} // namespace request
34
94class Response {
96 friend Request;
98 friend std::pair<fastly::expected<Response>,
99 std::vector<request::PendingRequest>>
100 request::select(std::vector<request::PendingRequest> &reqs);
101
102public:
108 // TODO(@zkat): Make this a "friend"?
111
118
125
127 static Response from_body(Body body);
128
131
142 static Response see_other(std::string_view destination);
143
154 static Response redirect(std::string_view destination);
155
166 static Response temporary_redirect(std::string_view destination);
167
170
172 bool has_body();
173
175 void set_body(Body body);
176
181
201 void append_body(Body body);
202
204 std::vector<uint8_t> into_body_bytes();
205
207 std::string into_body_string();
208
211
215
219
223
227
231 std::string take_body_string();
232
235 Response with_body_octet_stream(std::vector<uint8_t> body) &&;
236
239 void set_body_octet_stream(std::vector<uint8_t> body);
240
244 std::vector<uint8_t> take_body_bytes();
245
250 std::optional<std::string> get_content_type();
251
254 Response with_content_type(std::string_view mime) &&;
255
261 void set_content_type(std::string_view mime);
262
266 std::optional<size_t> get_content_length();
267
270
273 std::string_view value) &&;
274
277 std::string_view value) &&;
278
287 get_header(std::string_view name);
288
293
296 fastly::expected<void> set_header(std::string_view name,
297 std::string_view value);
298
304 std::string_view value);
305
309 remove_header(std::string_view name);
310
313
333 void set_status(StatusCode status);
334
336 Response with_version(Version version) &&;
337
339 Version get_version();
340
342 void set_version(Version version);
343
344 // TODO(@zkat): needs enum
345 // void set_framing_headers_mode(FramingHeadersMode mode);
346 // Response set_framing_headers_mode(FramingHeadersMode mode);
347
368 std::optional<std::string> get_backend_name();
369
393 std::optional<fastly::backend::Backend> get_backend();
394
417 std::optional<std::string> get_backend_addr();
418
445 std::optional<Request> take_backend_request();
446
484
536
545 std::optional<std::chrono::milliseconds> get_ttl();
546
550 std::optional<std::chrono::milliseconds> get_age();
551
556 std::optional<std::chrono::milliseconds> get_stale_while_revalidate();
557
558private:
559 auto &inner() { return res; }
560 Response(rust::Box<fastly::sys::http::Response> response)
561 : res(std::move(response)) {};
562 rust::Box<fastly::sys::http::Response> res;
563};
564
565} // namespace fastly::http
566
567namespace fastly {
568using fastly::http::Response;
569}
570
571#endif
Definition backend.h:21
Definition body.h:42
Definition request.h:149
Definition response.h:94
std::vector< uint8_t > into_body_bytes()
Consume the response and return its body as a byte vector.
std::optional< std::string > get_content_type()
std::optional< std::string > get_backend_addr()
Response clone_without_body()
void append_body(Body body)
static Response temporary_redirect(std::string_view destination)
StreamingBody stream_to_client()
std::string into_body_string()
Consume the response and return its body as a string.
Response with_content_type(std::string_view mime) &&
std::string take_body_string()
static Response from_status(StatusCode status)
Create a new response with the given status code.
static Response redirect(std::string_view destination)
fastly::expected< HeadersRange > get_headers()
std::optional< std::string > get_backend_name()
fastly::expected< Response > with_header(std::string_view name, std::string_view value) &&
Builder-style equivalent of Response::append_header().
void set_body_octet_stream(std::vector< uint8_t > body)
std::optional< fastly::backend::Backend > get_backend()
fastly::expected< Response > with_body_text_html(std::string_view body) &&
static Response see_other(std::string_view destination)
fastly::expected< HeaderValuesRange > get_header_all(std::string_view name)
Get an iterator of all the values of a header.
fastly::expected< Response > with_set_header(std::string_view name, std::string_view value) &&
Builder-style equivalent of Response::set_header().
void set_version(Version version)
Set the HTTP version of this response.
Response with_body_octet_stream(std::vector< uint8_t > body) &&
fastly::expected< std::optional< HeaderValue > > get_header(std::string_view name)
fastly::expected< Response > with_body_text_plain(std::string_view body) &&
Response with_version(Version version) &&
Builder-style equivalent of Response::set_version().
static Response from_body(Body body)
Create a new Response with the given value as the body.
Response with_status(StatusCode status) &&
Builder-style equivalent of Response::set_status().
fastly::expected< HeaderNamesRange > get_header_names()
fastly::expected< bool > contains_header(std::string_view name)
Returns whether the given header name is present in the response.
Version get_version()
Get the HTTP version of this response.
fastly::expected< void > set_body_text_html(std::string_view body)
void set_content_type(std::string_view mime)
Response with_body(Body body) &&
Builder-style equivalent of Response::set_body().
bool is_from_backend()
Return whether the response is from a backend request.
std::optional< Request > take_backend_request()
Response clone_with_body()
std::optional< size_t > get_content_length()
void set_body(Body body)
Set the given value as the response's body.
std::optional< std::chrono::milliseconds > get_age()
std::vector< uint8_t > take_body_bytes()
fastly::expected< std::optional< std::string > > remove_header(std::string_view name)
Body into_body()
Consume the response and return its body.
void set_status(StatusCode status)
fastly::expected< void > set_header(std::string_view name, std::string_view value)
std::optional< std::chrono::milliseconds > get_ttl()
fastly::expected< void > append_header(std::string_view name, std::string_view value)
bool has_body()
Returns true if this response has a body.
std::optional< std::chrono::milliseconds > get_stale_while_revalidate()
fastly::expected< void > set_body_text_plain(std::string_view body)
Definition status_code.h:14
Definition body.h:157
Definition backend.h:18
tl::expected< T, FastlyError > expected
Definition error.h:25
Definition body.h:29
std::pair< fastly::expected< fastly::http::Response >, std::vector< PendingRequest > > select(std::vector< PendingRequest > &reqs)
Definition backend.h:13
Definition backend.h:13
Definition access_bridge_internals.h:11