aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
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>
14
15#include <functional>
16#include <memory>
17
18namespace Aws
19{
20 namespace Crt
21 {
22 namespace Io
23 {
24 class ClientBootstrap;
25 }
26
27 namespace Http
28 {
29 class HttpClientConnection;
30 class HttpStream;
31 class HttpClientStream;
32 class HttpRequest;
33 class HttpProxyStrategy;
34 using HttpHeader = aws_http_header;
35
43 std::function<void(const std::shared_ptr<HttpClientConnection> &connection, int errorCode)>;
44
53 using OnConnectionShutdown = std::function<void(HttpClientConnection &connection, int errorCode)>;
54
63 using OnIncomingHeaders = std::function<void(
64 HttpStream &stream,
65 enum aws_http_header_block headerBlock,
66 const HttpHeader *headersArray,
67 std::size_t headersCount)>;
68
76 std::function<void(HttpStream &stream, enum aws_http_header_block block)>;
77
84 using OnIncomingBody = std::function<void(HttpStream &stream, const ByteCursor &data)>;
85
94 using OnStreamComplete = std::function<void(HttpStream &stream, int errorCode)>;
95
100 {
101
116 };
117
122 class AWS_CRT_CPP_API HttpStream : public std::enable_shared_from_this<HttpStream>
123 {
124 public:
125 virtual ~HttpStream();
126 HttpStream(const HttpStream &) = delete;
127 HttpStream(HttpStream &&) = delete;
128 HttpStream &operator=(const HttpStream &) = delete;
130
134 HttpClientConnection &GetConnection() const noexcept;
135
136 virtual int GetResponseStatusCode() const noexcept = 0;
137
147 void UpdateWindow(std::size_t incrementSize) noexcept;
148
149 protected:
150 aws_http_stream *m_stream;
151 std::shared_ptr<HttpClientConnection> m_connection;
152 HttpStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
153
154 private:
155 OnIncomingHeaders m_onIncomingHeaders;
156 OnIncomingHeadersBlockDone m_onIncomingHeadersBlockDone;
157 OnIncomingBody m_onIncomingBody;
158 OnStreamComplete m_onStreamComplete;
159
160 static int s_onIncomingHeaders(
161 struct aws_http_stream *stream,
162 enum aws_http_header_block headerBlock,
163 const struct aws_http_header *headerArray,
164 size_t numHeaders,
165 void *userData) noexcept;
166 static int s_onIncomingHeaderBlockDone(
167 struct aws_http_stream *stream,
168 enum aws_http_header_block headerBlock,
169 void *userData) noexcept;
170 static int s_onIncomingBody(
171 struct aws_http_stream *stream,
172 const struct aws_byte_cursor *data,
173 void *userData) noexcept;
174 static void s_onStreamComplete(struct aws_http_stream *stream, int errorCode, void *userData) noexcept;
175
177 };
178
180 {
181 ClientStreamCallbackData() : allocator(nullptr), stream(nullptr) {}
183 std::shared_ptr<HttpStream> stream;
184 };
185
187 {
188 public:
194
199 virtual int GetResponseStatusCode() const noexcept override;
200
206 bool Activate() noexcept;
207
208 private:
209 HttpClientStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
210
211 ClientStreamCallbackData m_callbackData;
213 };
214
222 {
223 None,
224 Basic,
225 };
226
227 /*
228 * Mirror of aws_http_proxy_connection_type enum
229 */
231 {
239 Legacy = AWS_HPCT_HTTP_LEGACY,
240
245 Forwarding = AWS_HPCT_HTTP_FORWARD,
246
251 Tunneling = AWS_HPCT_HTTP_TUNNEL,
252 };
253
258 {
259 public:
263
266
268
279 void InitializeRawProxyOptions(struct aws_http_proxy_options &raw_options) const;
280
286
291 uint16_t Port;
292
298
303
308 std::shared_ptr<HttpProxyStrategy> ProxyStrategy;
309
319
325
331 };
332
337 {
338 public:
342
344
347
353
358
365
372
378
383 uint16_t Port;
384
390
396
402
411 };
412 enum class HttpVersion
413 {
414 Unknown = AWS_HTTP_VERSION_UNKNOWN,
415 Http1_0 = AWS_HTTP_VERSION_1_0,
416 Http1_1 = AWS_HTTP_VERSION_1_1,
417 Http2 = AWS_HTTP_VERSION_2,
418 };
422 class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
423 {
424 public:
425 virtual ~HttpClientConnection() = default;
430
443 std::shared_ptr<HttpClientStream> NewClientStream(const HttpRequestOptions &requestOptions) noexcept;
444
448 bool IsOpen() const noexcept;
449
457 void Close() noexcept;
458
462 HttpVersion GetVersion() noexcept;
466 int LastError() const noexcept { return m_lastError; }
467
476 static bool CreateConnection(
477 const HttpClientConnectionOptions &connectionOptions,
478 Allocator *allocator) noexcept;
479
480 protected:
481 HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
482 aws_http_connection *m_connection;
483
484 private:
485 Allocator *m_allocator;
486 int m_lastError;
487
488 static void s_onClientConnectionSetup(
489 struct aws_http_connection *connection,
490 int error_code,
491 void *user_data) noexcept;
492 static void s_onClientConnectionShutdown(
493 struct aws_http_connection *connection,
494 int error_code,
495 void *user_data) noexcept;
496 };
497
498 } // namespace Http
499 } // namespace Crt
500} // namespace Aws
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Definition: HttpConnection.h:423
HttpClientConnection & operator=(HttpClientConnection &&)=delete
aws_http_connection * m_connection
Definition: HttpConnection.h:482
HttpClientConnection & operator=(const HttpClientConnection &)=delete
HttpClientConnection(const HttpClientConnection &)=delete
HttpClientConnection(HttpClientConnection &&)=delete
Definition: HttpConnection.h:337
Optional< HttpClientConnectionProxyOptions > ProxyOptions
Definition: HttpConnection.h:401
HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs)=default
HttpClientConnectionOptions & operator=(const HttpClientConnectionOptions &rhs)=default
uint16_t Port
Definition: HttpConnection.h:383
Optional< Io::TlsConnectionOptions > TlsOptions
Definition: HttpConnection.h:395
size_t InitialWindowSize
Definition: HttpConnection.h:357
HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs)=default
OnConnectionSetup OnConnectionSetupCallback
Definition: HttpConnection.h:364
Io::SocketOptions SocketOptions
Definition: HttpConnection.h:389
String HostName
Definition: HttpConnection.h:377
OnConnectionShutdown OnConnectionShutdownCallback
Definition: HttpConnection.h:371
Io::ClientBootstrap * Bootstrap
Definition: HttpConnection.h:352
HttpClientConnectionOptions & operator=(HttpClientConnectionOptions &&rhs)=default
bool ManualWindowManagement
Definition: HttpConnection.h:410
Definition: HttpConnection.h:258
HttpClientConnectionProxyOptions & operator=(const HttpClientConnectionProxyOptions &rhs)=default
AwsHttpProxyConnectionType ProxyConnectionType
Definition: HttpConnection.h:302
HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs)=default
HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition: HttpConnection.h:297
String BasicAuthPassword
Definition: HttpConnection.h:330
std::shared_ptr< HttpProxyStrategy > ProxyStrategy
Definition: HttpConnection.h:308
AwsHttpProxyAuthenticationType AuthType
Definition: HttpConnection.h:318
String BasicAuthUsername
Definition: HttpConnection.h:324
HttpClientConnectionProxyOptions & operator=(HttpClientConnectionProxyOptions &&rhs)=default
uint16_t Port
Definition: HttpConnection.h:291
String HostName
Definition: HttpConnection.h:285
Definition: HttpConnection.h:187
HttpClientStream & operator=(const HttpClientStream &)=delete
HttpClientStream & operator=(HttpClientStream &&)=delete
HttpClientStream(const HttpClientStream &)=delete
HttpClientStream(HttpClientStream &&)=delete
Definition: HttpRequestResponse.h:73
Definition: HttpConnection.h:123
HttpStream(const HttpStream &)=delete
HttpStream & operator=(const HttpStream &)=delete
HttpStream(HttpStream &&)=delete
HttpStream & operator=(HttpStream &&)=delete
Definition: Bootstrap.h:35
Definition: SocketOptions.h:45
Definition: Optional.h:13
aws_http_header HttpHeader
Definition: HttpConnection.h:34
std::function< void(HttpClientConnection &connection, int errorCode)> OnConnectionShutdown
Definition: HttpConnection.h:53
AwsHttpProxyConnectionType
Definition: HttpConnection.h:231
std::function< void(HttpStream &stream, int errorCode)> OnStreamComplete
Definition: HttpConnection.h:94
std::function< void(HttpStream &stream, enum aws_http_header_block block)> OnIncomingHeadersBlockDone
Definition: HttpConnection.h:76
std::function< void(HttpStream &stream, enum aws_http_header_block headerBlock, const HttpHeader *headersArray, std::size_t headersCount)> OnIncomingHeaders
Definition: HttpConnection.h:67
std::function< void(HttpStream &stream, const ByteCursor &data)> OnIncomingBody
Definition: HttpConnection.h:84
std::function< void(const std::shared_ptr< HttpClientConnection > &connection, int errorCode)> OnConnectionSetup
Definition: HttpConnection.h:43
AwsHttpProxyAuthenticationType
Definition: HttpConnection.h:222
HttpVersion
Definition: HttpConnection.h:413
aws_byte_cursor ByteCursor
Definition: Types.h:33
aws_allocator Allocator
Definition: StlAllocator.h:17
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
AWS_CRT_CPP_API int LastError() noexcept
Definition: Api.cpp:315
Definition: Api.h:17
Definition: StringView.h:846
Definition: HttpConnection.h:180
ClientStreamCallbackData()
Definition: HttpConnection.h:181
Allocator * allocator
Definition: HttpConnection.h:182
std::shared_ptr< HttpStream > stream
Definition: HttpConnection.h:183
Definition: HttpConnection.h:100
OnStreamComplete onStreamComplete
Definition: HttpConnection.h:115
OnIncomingHeaders onIncomingHeaders
Definition: HttpConnection.h:106
OnIncomingHeadersBlockDone onIncomingHeadersBlockDone
Definition: HttpConnection.h:107
HttpRequest * request
Definition: HttpConnection.h:102
OnIncomingBody onIncomingBody
Definition: HttpConnection.h:111