aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
HttpConnection.h
Go to the documentation of this file.
1#pragma once
6#include <aws/http/connection.h>
7#include <aws/http/proxy.h>
8#include <aws/http/request_response.h>
9
10#include <aws/crt/Types.h>
13#include <aws/crt/io/Stream.h>
15
16#include <functional>
17#include <memory>
18
19namespace Aws
20{
21 namespace Crt
22 {
23 namespace Io
24 {
25 class ClientBootstrap;
26 class L4ProxyConfig;
27 } // namespace Io
28
29 namespace Http
30 {
31 class HttpClientConnection;
32 class HttpStream;
33 class HttpClientStream;
34 class HttpRequest;
35 class HttpProxyStrategy;
36 using HttpHeader = aws_http_header;
37
45 std::function<void(const std::shared_ptr<HttpClientConnection> &connection, int errorCode)>;
46
55 using OnConnectionShutdown = std::function<void(HttpClientConnection &connection, int errorCode)>;
56
65 using OnIncomingHeaders = std::function<void(
66 HttpStream &stream,
67 enum aws_http_header_block headerBlock,
68 const HttpHeader *headersArray,
69 std::size_t headersCount)>;
70
78 std::function<void(HttpStream &stream, enum aws_http_header_block block)>;
79
86 using OnIncomingBody = std::function<void(HttpStream &stream, const ByteCursor &data)>;
87
96 using OnStreamComplete = std::function<void(HttpStream &stream, int errorCode)>;
97
145
150 class AWS_CRT_CPP_API HttpStream : public std::enable_shared_from_this<HttpStream>
151 {
152 public:
153 virtual ~HttpStream();
154 HttpStream(const HttpStream &) = delete;
155 HttpStream(HttpStream &&) = delete;
156 HttpStream &operator=(const HttpStream &) = delete;
158
162 HttpClientConnection &GetConnection() const noexcept;
163
167 virtual int GetResponseStatusCode() const noexcept = 0;
168
178 void UpdateWindow(std::size_t incrementSize) noexcept;
179
180 protected:
181 aws_http_stream *m_stream;
182 std::shared_ptr<HttpClientConnection> m_connection;
183 HttpStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
184
185 private:
186 OnIncomingHeaders m_onIncomingHeaders;
187 OnIncomingHeadersBlockDone m_onIncomingHeadersBlockDone;
188 OnIncomingBody m_onIncomingBody;
189 OnStreamComplete m_onStreamComplete;
190
191 static int s_onIncomingHeaders(
192 struct aws_http_stream *stream,
193 enum aws_http_header_block headerBlock,
194 const struct aws_http_header *headerArray,
195 size_t numHeaders,
196 void *userData) noexcept;
197 static int s_onIncomingHeaderBlockDone(
198 struct aws_http_stream *stream,
199 enum aws_http_header_block headerBlock,
200 void *userData) noexcept;
201 static int s_onIncomingBody(
202 struct aws_http_stream *stream,
203 const struct aws_byte_cursor *data,
204 void *userData) noexcept;
205 static void s_onStreamComplete(struct aws_http_stream *stream, int errorCode, void *userData) noexcept;
206
208 };
209
211 {
212 ClientStreamCallbackData() : allocator(nullptr), stream(nullptr) {}
214 std::shared_ptr<HttpStream> stream;
215 };
216
217 using OnWriteDataComplete = std::function<void(std::shared_ptr<HttpStream> &stream, int errorCode)>;
218
223 {
224 public:
230
235 virtual int GetResponseStatusCode() const noexcept override;
236
242 bool Activate() noexcept;
243
244 int WriteData(
245 std::shared_ptr<Aws::Crt::Io::InputStream> stream,
246 const OnWriteDataComplete &onComplete,
247 bool endStream = false) noexcept;
248
249 private:
250 HttpClientStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
251
252 ClientStreamCallbackData m_callbackData;
254 };
255
263 {
264 None,
265 Basic,
266 };
267
273 {
281 Legacy = AWS_HPCT_HTTP_LEGACY,
282
287 Forwarding = AWS_HPCT_HTTP_FORWARD,
288
293 Tunneling = AWS_HPCT_HTTP_TUNNEL,
294 };
295
372
377 {
382 Disabled = AWS_HPEV_DISABLE,
391 Enabled = AWS_HPEV_ENABLE,
392 };
393
398 {
399 public:
403
406
408
417 void InitializeRawProxyOptions(struct proxy_env_var_settings &raw_options) const;
418
423
431
437 };
438
525
526 enum class HttpVersion
527 {
528 Unknown = AWS_HTTP_VERSION_UNKNOWN,
529 Http1_0 = AWS_HTTP_VERSION_1_0,
530 Http1_1 = AWS_HTTP_VERSION_1_1,
531 Http2 = AWS_HTTP_VERSION_2,
532 };
533
537 class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
538 {
539 public:
540 virtual ~HttpClientConnection() = default;
545
558 std::shared_ptr<HttpClientStream> NewClientStream(const HttpRequestOptions &requestOptions) noexcept;
559
563 bool IsOpen() const noexcept;
564
572 void Close() noexcept;
573
577 HttpVersion GetVersion() noexcept;
578
582 int LastError() const noexcept { return m_lastError; }
583
592 static bool CreateConnection(
593 const HttpClientConnectionOptions &connectionOptions,
594 Allocator *allocator) noexcept;
595
596 protected:
597 HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
598 aws_http_connection *m_connection;
599
600 private:
601 Allocator *m_allocator;
602 int m_lastError;
603
604 static void s_onClientConnectionSetup(
605 struct aws_http_connection *connection,
606 int error_code,
607 void *user_data) noexcept;
608 static void s_onClientConnectionShutdown(
609 struct aws_http_connection *connection,
610 int error_code,
611 void *user_data) noexcept;
612 };
613
614 } // namespace Http
615 } // namespace Crt
616} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition HttpConnection.h:538
HttpClientConnection & operator=(HttpClientConnection &&)=delete
aws_http_connection * m_connection
Definition HttpConnection.h:598
HttpClientConnection & operator=(const HttpClientConnection &)=delete
HttpClientConnection(const HttpClientConnection &)=delete
HttpClientConnection(HttpClientConnection &&)=delete
Definition HttpConnection.h:443
Optional< HttpClientConnectionProxyOptions > ProxyOptions
Definition HttpConnection.h:508
HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs)=default
HttpClientConnectionOptions & operator=(const HttpClientConnectionOptions &rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:502
std::shared_ptr< Aws::Crt::Io::L4ProxyConfig > L4ProxyOptions
Definition HttpConnection.h:514
size_t InitialWindowSize
Definition HttpConnection.h:464
HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs)=default
OnConnectionSetup OnConnectionSetupCallback
Definition HttpConnection.h:471
Io::SocketOptions SocketOptions
Definition HttpConnection.h:496
String HostName
Definition HttpConnection.h:484
OnConnectionShutdown OnConnectionShutdownCallback
Definition HttpConnection.h:478
Io::ClientBootstrap * Bootstrap
Definition HttpConnection.h:459
HttpClientConnectionOptions & operator=(HttpClientConnectionOptions &&rhs)=default
bool ManualWindowManagement
Definition HttpConnection.h:523
uint32_t Port
Definition HttpConnection.h:490
HttpClientConnectionProxyOptions & operator=(const HttpClientConnectionProxyOptions &rhs)=default
AwsHttpProxyConnectionType ProxyConnectionType
Definition HttpConnection.h:342
HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs)=default
HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:337
String BasicAuthPassword
Definition HttpConnection.h:370
uint32_t Port
Definition HttpConnection.h:331
std::shared_ptr< HttpProxyStrategy > ProxyStrategy
Definition HttpConnection.h:348
AwsHttpProxyAuthenticationType AuthType
Definition HttpConnection.h:358
String BasicAuthUsername
Definition HttpConnection.h:364
HttpClientConnectionProxyOptions & operator=(HttpClientConnectionProxyOptions &&rhs)=default
String HostName
Definition HttpConnection.h:325
Definition HttpConnection.h:223
HttpClientStream & operator=(const HttpClientStream &)=delete
HttpClientStream & operator=(HttpClientStream &&)=delete
HttpClientStream(const HttpClientStream &)=delete
HttpClientStream(HttpClientStream &&)=delete
Definition HttpRequestResponse.h:110
Definition HttpConnection.h:151
HttpStream(const HttpStream &)=delete
HttpStream & operator=(const HttpStream &)=delete
HttpStream(HttpStream &&)=delete
HttpStream & operator=(HttpStream &&)=delete
Definition HttpConnection.h:398
ProxyEnvVarOptions & operator=(const ProxyEnvVarOptions &rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:436
ProxyEnvVarOptions & operator=(ProxyEnvVarOptions &&rhs)=default
ProxyEnvVarOptions(const ProxyEnvVarOptions &rhs)=default
ProxyEnvVarType proxyEnvVarType
Definition HttpConnection.h:422
ProxyEnvVarOptions(ProxyEnvVarOptions &&rhs)=default
AwsHttpProxyConnectionType connectionType
Definition HttpConnection.h:430
Definition Bootstrap.h:35
Definition SocketOptions.h:70
Definition Optional.h:19
aws_http_header HttpHeader
Definition HttpConnection.h:36
std::function< void(HttpClientConnection &connection, int errorCode)> OnConnectionShutdown
Definition HttpConnection.h:55
AwsHttpProxyConnectionType
Definition HttpConnection.h:273
std::function< void(HttpStream &stream, int errorCode)> OnStreamComplete
Definition HttpConnection.h:96
ProxyEnvVarType
Definition HttpConnection.h:377
std::function< void(HttpStream &stream, enum aws_http_header_block block)> OnIncomingHeadersBlockDone
Definition HttpConnection.h:78
std::function< void(std::shared_ptr< HttpStream > &stream, int errorCode)> OnWriteDataComplete
Definition HttpConnection.h:217
std::function< void(HttpStream &stream, enum aws_http_header_block headerBlock, const HttpHeader *headersArray, std::size_t headersCount)> OnIncomingHeaders
Definition HttpConnection.h:69
std::function< void(HttpStream &stream, const ByteCursor &data)> OnIncomingBody
Definition HttpConnection.h:86
std::function< void(const std::shared_ptr< HttpClientConnection > &connection, int errorCode)> OnConnectionSetup
Definition HttpConnection.h:45
AwsHttpProxyAuthenticationType
Definition HttpConnection.h:263
HttpVersion
Definition HttpConnection.h:527
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition Types.h:45
Definition Allocator.h:11
Definition StringView.h:862
Definition HttpConnection.h:211
ClientStreamCallbackData()
Definition HttpConnection.h:212
Allocator * allocator
Definition HttpConnection.h:213
std::shared_ptr< HttpStream > stream
Definition HttpConnection.h:214
Definition HttpConnection.h:102
OnStreamComplete onStreamComplete
Definition HttpConnection.h:122
OnIncomingHeaders onIncomingHeaders
Definition HttpConnection.h:111
OnIncomingHeadersBlockDone onIncomingHeadersBlockDone
Definition HttpConnection.h:112
HttpRequest * request
Definition HttpConnection.h:106
OnIncomingBody onIncomingBody
Definition HttpConnection.h:117