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
162 static fastly::expected<Request> create(std::string_view method,
163 std::string_view url);
164
167 static Request get(std::string_view url);
168
171 static Request head(std::string_view url);
172
175 static Request post(std::string_view url);
176
179 static Request put(std::string_view url);
180
183 static Request delete_(std::string_view url);
184
187 static Request connect(std::string_view url);
188
191 static Request options(std::string_view url);
192
195 static Request trace(std::string_view url);
196
199 static Request patch(std::string_view url);
200
209
213
234
241
263 fastly::expected<Response> send(std::string_view backend_name);
264
308 send_async(std::string_view backend_name);
309
363 send_async_streaming(std::string_view backend_name);
364
367
369 bool has_body();
370
375
377 void set_body(Body body);
378
399 void append_body(Body &body);
400
402 std::vector<uint8_t> into_body_bytes();
403
405 std::string into_body_string();
406
409
413
417
421
425
429 std::string take_body_string();
430
433 Request with_body_octet_stream(std::vector<uint8_t> body) &&;
434
437 void set_body_octet_stream(std::vector<uint8_t> body);
438
442 std::vector<uint8_t> take_body_bytes();
443
444 // ChunksIter read_body_chunks(size_t chunk_size);
445
450 std::optional<std::string> get_content_type();
451
454 Request with_content_type(std::string_view mime) &&;
455
461 void set_content_type(std::string_view mime);
462
466 std::optional<size_t> get_content_length();
467
470
473 std::string_view value) &&;
474
477 std::string_view value) &&;
478
487 get_header(std::string_view name);
488
493
496 fastly::expected<void> set_header(std::string_view name,
497 std::string_view value);
498
504 std::string_view value);
505
509 remove_header(std::string_view name);
510
512 Request with_method(Method method) &&;
513
517 fastly::expected<Request> with_method(std::string_view method) &&;
518
520 Method get_method();
521
525 std::string get_method_str();
526
528 void set_method(Method method);
529
533 fastly::expected<void> set_method(std::string_view method);
534
536 fastly::expected<Request> with_url(std::string_view url) &&;
537
539 std::string get_url();
540
542 fastly::expected<void> set_url(std::string_view url);
543
552 std::string get_path();
553
555 fastly::expected<Request> with_path(std::string_view path) &&;
556
565 fastly::expected<void> set_path(std::string_view path);
566
569 std::optional<std::string> get_query_string();
570
576 std::optional<std::string> get_query_parameter(std::string_view param);
577
580
593
596
598 Request with_version(Version version) &&;
599
601 Version get_version();
602
604 void set_version(Version version);
605
607 Request with_pass(bool pass) &&;
608
620 void set_pass(bool pass);
621
623 Request with_ttl(uint32_t ttl) &&;
624
632 void set_ttl(uint32_t ttl);
633
637
645 void set_stale_while_revalidate(uint32_t swr);
646
648 Request with_pci(bool pci) &&;
649
663 void set_pci(bool pci);
664
668
688
689 std::optional<std::string> get_client_ip_addr();
690 std::optional<std::string> get_server_ip_addr();
691
692 std::optional<OriginalHeaderNamesRange> get_original_header_names();
693 std::optional<uint32_t> get_original_header_count();
694
698 std::optional<bool> get_client_ddos_detected();
699
700 // std::optional<std::vector<uint8_t>> get_tls_client_hello();
701 // std::optional<std::array<uint8_t, 16>> get_tls_ja3_md5();
702 // std::optional<std::string> get_tls_ja4();
703 // std::optional<std::string> get_tls_raw_client_certificate();
704 // std::optional<std::vector<uint8_t>>
705 // get_tls_raw_client_certificate_bytes();
706 // // TODO(@zkat): needs additional type
707 // // std::optional<ClientCertVerifyResult>
708 // get_tls_client_cert_verify_result(); std::optional<std::string>
709 // get_tls_cipher_openssl_name(); std::optional<std::vector<uint8_t>>
710 // get_tls_cipher_openssl_name_bytes(); std::optional<std::vector<uint8_t>>
711 // get_tls_protocol_bytes();
712
726
730
731 // TODO(@zkat): needs enum
732 // void set_framing_headers_mode(FramingHeadersMode mode);
733 // Request *set_framing_headers_mode(FramingHeadersMode mode);
734
741
742 // void handoff_websocket(fastly::backend::Backend backend);
743 // void handoff_fanout(fastly::backend::Backend backend);
744 // Request *on_behalf_of(std::string_view service);
745
748 void set_cache_key(std::string_view key);
749
752 void set_cache_key(std::vector<uint8_t> key);
753
755 Request with_cache_key(std::string_view key) &&;
756
758 Request with_cache_key(std::vector<uint8_t> key) &&;
759
762
763private:
764 auto &inner() { return req; }
765 Request(rust::Box<fastly::sys::http::Request> r) : req(std::move(r)) {};
766 rust::Box<fastly::sys::http::Request> req;
767};
768
769} // namespace fastly::http
770
771namespace fastly {
772using fastly::http::Request;
773}
774
775#endif
Definition backend.h:23
Definition body.h:49
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< Request > with_method(std::string_view method) &&
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)
static fastly::expected< Request > create(std::string_view 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)
std::string get_method_str()
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< void > set_method(std::string_view method)
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:168
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:36
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