Fastly Compute C++ SDK
Loading...
Searching...
No Matches
request.h
Go to the documentation of this file.
1#ifndef FASTLY_HTTP_REQUEST_H
2#define FASTLY_HTTP_REQUEST_H
3
4#include <algorithm>
5#include <fastly/backend.h>
7#include <fastly/error.h>
8#include <fastly/http/body.h>
10#include <fastly/http/http.h>
12#include <fastly/sdk-sys.h>
13#include <iostream>
14#include <iterator>
15#include <optional>
16#include <string>
17#include <string_view>
18#include <utility>
19#include <variant>
20#include <vector>
21
22namespace fastly::backend {
23class Backend;
24}
25
26namespace fastly::http {
27
28class Body;
29class StreamingBody;
30class Response;
31class Request;
32
33namespace request {
34
43class PendingRequest {
45 friend Request;
46 friend std::pair<fastly::expected<Response>, std::vector<PendingRequest>>
47 select(std::vector<PendingRequest> &reqs);
48
55 std::variant<PendingRequest, fastly::expected<Response>> poll();
56
62
66 Request cloned_sent_req();
67
68private:
69 auto &inner() { return req; }
70 rust::Box<fastly::sys::http::request::PendingRequest> req;
71
72 PendingRequest(rust::Box<fastly::sys::http::request::PendingRequest> r)
73 : req(std::move(r)) {};
74};
75
90std::pair<fastly::expected<Response>, std::vector<PendingRequest>>
91select(std::vector<PendingRequest> &reqs);
92
93} // namespace request
94
149class Request {
151 friend Response;
153
154public:
157 Request(Method method, std::string_view url);
158
161 static Request get(std::string_view url);
162
165 static Request head(std::string_view url);
166
169 static Request post(std::string_view url);
170
173 static Request put(std::string_view url);
174
177 static Request delete_(std::string_view url);
178
181 static Request connect(std::string_view url);
182
185 static Request options(std::string_view url);
186
189 static Request trace(std::string_view url);
190
193 static Request patch(std::string_view url);
194
203
207
228
235
257 fastly::expected<Response> send(std::string_view backend_name);
258
302 send_async(std::string_view backend_name);
303
357 send_async_streaming(std::string_view backend_name);
358
361
363 bool has_body();
364
369
371 void set_body(Body body);
372
393 void append_body(Body &body);
394
396 std::vector<uint8_t> into_body_bytes();
397
399 std::string into_body_string();
400
403
407
411
415
419
423 std::string take_body_string();
424
427 Request with_body_octet_stream(std::vector<uint8_t> body) &&;
428
431 void set_body_octet_stream(std::vector<uint8_t> body);
432
436 std::vector<uint8_t> take_body_bytes();
437
438 // ChunksIter read_body_chunks(size_t chunk_size);
439
444 std::optional<std::string> get_content_type();
445
448 Request with_content_type(std::string_view mime) &&;
449
455 void set_content_type(std::string_view mime);
456
460 std::optional<size_t> get_content_length();
461
464
467 std::string_view value) &&;
468
471 std::string_view value) &&;
472
481 get_header(std::string_view name);
482
487
490 fastly::expected<void> set_header(std::string_view name,
491 std::string_view value);
492
498 std::string_view value);
499
503 remove_header(std::string_view name);
504
506 Request with_method(Method method) &&;
507
509 Method get_method();
510
512 void set_method(Method method);
513
515 fastly::expected<Request> with_url(std::string_view url) &&;
516
518 std::string get_url();
519
521 fastly::expected<void> set_url(std::string_view url);
522
531 std::string get_path();
532
534 fastly::expected<Request> with_path(std::string_view path) &&;
535
544 fastly::expected<void> set_path(std::string_view path);
545
548 std::optional<std::string> get_query_string();
549
555 std::optional<std::string> get_query_parameter(std::string_view param);
556
559
572
575
577 Request with_version(Version version) &&;
578
580 Version get_version();
581
583 void set_version(Version version);
584
586 Request with_pass(bool pass) &&;
587
599 void set_pass(bool pass);
600
602 Request with_ttl(uint32_t ttl) &&;
603
611 void set_ttl(uint32_t ttl);
612
616
624 void set_stale_while_revalidate(uint32_t swr);
625
627 Request with_pci(bool pci) &&;
628
642 void set_pci(bool pci);
643
647
667
668 std::optional<std::string> get_client_ip_addr();
669 std::optional<std::string> get_server_ip_addr();
670
671 std::optional<OriginalHeaderNamesRange> get_original_header_names();
672 std::optional<uint32_t> get_original_header_count();
673
677 std::optional<bool> get_client_ddos_detected();
678
679 // std::optional<std::vector<uint8_t>> get_tls_client_hello();
680 // std::optional<std::array<uint8_t, 16>> get_tls_ja3_md5();
681 // std::optional<std::string> get_tls_ja4();
682 // std::optional<std::string> get_tls_raw_client_certificate();
683 // std::optional<std::vector<uint8_t>>
684 // get_tls_raw_client_certificate_bytes();
685 // // TODO(@zkat): needs additional type
686 // // std::optional<ClientCertVerifyResult>
687 // get_tls_client_cert_verify_result(); std::optional<std::string>
688 // get_tls_cipher_openssl_name(); std::optional<std::vector<uint8_t>>
689 // get_tls_cipher_openssl_name_bytes(); std::optional<std::vector<uint8_t>>
690 // get_tls_protocol_bytes();
691
705
709
710 // TODO(@zkat): needs enum
711 // void set_framing_headers_mode(FramingHeadersMode mode);
712 // Request *set_framing_headers_mode(FramingHeadersMode mode);
713
720
721 // void handoff_websocket(fastly::backend::Backend backend);
722 // void handoff_fanout(fastly::backend::Backend backend);
723 // Request *on_behalf_of(std::string_view service);
724
727 void set_cache_key(std::string_view key);
728
731 void set_cache_key(std::vector<uint8_t> key);
732
734 Request with_cache_key(std::string_view key) &&;
735
737 Request with_cache_key(std::vector<uint8_t> key) &&;
738
741
742private:
743 auto &inner() { return req; }
744 Request(rust::Box<fastly::sys::http::Request> r) : req(std::move(r)) {};
745 rust::Box<fastly::sys::http::Request> req;
746};
747
748} // namespace fastly::http
749
750namespace fastly {
751using fastly::http::Request;
752}
753
754#endif
Definition backend.h:21
Definition body.h:42
Definition request.h:149
static Request from_client()
static Request patch(std::string_view url)
fastly::expected< std::optional< HeaderValue > > get_header(std::string_view name)
fastly::expected< std::pair< StreamingBody, request::PendingRequest > > send_async_streaming(std::string_view backend_name)
std::string into_body_string()
Consume the request and return its body as a string.
fastly::expected< HeadersRange > get_headers()
fastly::expected< std::optional< std::string > > remove_header(std::string_view name)
fastly::expected< Response > send(fastly::backend::Backend &backend)
void set_version(Version version)
Set the HTTP version of this request.
static Request put(std::string_view url)
void set_pass(bool pass)
static Request trace(std::string_view url)
static Request post(std::string_view url)
static Request get(std::string_view url)
fastly::expected< Request > with_body_text_html(std::string_view body) &&
void set_pci(bool pci)
void set_content_type(std::string_view mime)
bool has_body()
Returns true if this request has a body.
fastly::expected< Request > with_header(std::string_view name, std::string_view value) &&
Builder-style equivalent of Request::append_header().
static Request delete_(std::string_view url)
bool is_cacheable()
Gets whether the request is potentially cacheable.
fastly::expected< bool > contains_header(std::string_view name)
Returns whether the given header name is present in the request.
std::string get_url()
Get the request URL as a string.
std::optional< OriginalHeaderNamesRange > get_original_header_names()
Request clone_without_body()
fastly::expected< request::PendingRequest > send_async(std::string_view backend_name)
Body into_body()
Consume the request and return its body as a Body instance.
Request(Method method, std::string_view url)
fastly::expected< request::PendingRequest > send_async(fastly::backend::Backend &backend)
fastly::expected< void > set_url(std::string_view url)
Set the request URL.
Request with_version(Version version) &&
Builder-style equivalent of Request::set_version().
static Request options(std::string_view url)
fastly::expected< void > set_query_string(std::string_view query)
fastly::expected< Request > with_surrogate_key(std::string_view sk) &&
static Request head(std::string_view url)
std::optional< uint32_t > get_original_header_count()
fastly::expected< Request > with_path(std::string_view path) &&
Builder-style equivalent of Request::set_path().
fastly::expected< Request > with_set_header(std::string_view name, std::string_view value) &&
Builder-style equivalent of Request::set_header().
fastly::expected< void > set_surrogate_key(std::string_view sk)
fastly::expected< void > set_body_text_html(std::string_view body)
void set_auto_decompress_gzip(bool gzip)
static Request connect(std::string_view url)
Request with_body_octet_stream(std::vector< uint8_t > body) &&
Version get_version()
Get the HTTP version of this request.
std::optional< size_t > get_content_length()
fastly::expected< HeaderValuesRange > get_header_all(std::string_view name)
Get an iterator of all the values of a header.
fastly::expected< void > set_body_text_plain(std::string_view body)
std::vector< uint8_t > take_body_bytes()
Request with_method(Method method) &&
Builder-style equivalent of Request::set_method().
Request with_content_type(std::string_view mime) &&
std::vector< uint8_t > into_body_bytes()
Consume the request and return its body as a byte vector.
std::optional< std::string > get_content_type()
fastly::expected< Response > send(std::string_view backend_name)
std::string get_path()
fastly::expected< Request > with_body_text_plain(std::string_view body) &&
std::optional< std::string > get_server_ip_addr()
fastly::expected< HeaderNamesRange > get_header_names()
void set_cache_key(std::vector< uint8_t > key)
fastly::expected< void > set_path(std::string_view path)
Method get_method()
Get the request method.
Request with_auto_decompress_gzip(bool gzip) &&
Request with_ttl(uint32_t ttl) &&
Builder-style equivalent of Request::set_ttl().
fastly::expected< Request > with_query_string(std::string_view query) &&
Builder-style equivalent of Request::set_query().
std::string take_body_string()
void set_method(Method method)
Set the request method.
void set_body(Body body)
Set the given value as the request's body.
void set_cache_key(std::string_view key)
fastly::expected< void > append_header(std::string_view name, std::string_view value)
Request with_body(Body body) &&
Builder-style equivalent of Request::set_body().
std::optional< std::string > get_query_parameter(std::string_view param)
std::optional< std::string > get_client_ip_addr()
fastly::expected< Request > with_url(std::string_view url) &&
Builder-style equivalent of Request::set_url().
Request with_stale_while_revalidate(uint32_t swr) &&
void set_body_octet_stream(std::vector< uint8_t > body)
fastly::expected< std::pair< StreamingBody, request::PendingRequest > > send_async_streaming(fastly::backend::Backend &backend)
std::optional< std::string > get_query_string()
std::optional< bool > get_client_ddos_detected()
void remove_query()
Remove the query component from the request URL, if one exists.
Request with_pci(bool pci) &&
Builder-style equivalent of Request::set_pci().
void set_stale_while_revalidate(uint32_t swr)
void append_body(Body &body)
Request with_pass(bool pass) &&
Builder-style equivalent of Request::set_pass().
void set_ttl(uint32_t ttl)
Request with_cache_key(std::string_view key) &&
Builder-style equivalent of Request::set_cache_key().
fastly::expected< void > set_header(std::string_view name, std::string_view value)
Request with_cache_key(std::vector< uint8_t > key) &&
Builder-style equivalent of Request::set_cache_key().
Definition response.h:94
Definition body.h:157
friend std::pair< fastly::expected< Response >, std::vector< PendingRequest > > select(std::vector< PendingRequest > &reqs)
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