AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/http/HttpConnection.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

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>
11#include <aws/crt/io/Bootstrap.h>
12#include <aws/crt/io/SocketOptions.h>
13#include <aws/crt/io/TlsOptions.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
42 using OnConnectionSetup =
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
75 using OnIncomingHeadersBlockDone =
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
99 struct AWS_CRT_CPP_API HttpRequestOptions
100 {
104 HttpRequest *request;
105
109 OnIncomingHeaders onIncomingHeaders;
110 OnIncomingHeadersBlockDone onIncomingHeadersBlockDone;
111
115 OnIncomingBody onIncomingBody;
116
120 OnStreamComplete onStreamComplete;
121 };
122
127 class AWS_CRT_CPP_API HttpStream : public std::enable_shared_from_this<HttpStream>
128 {
129 public:
130 virtual ~HttpStream();
131 HttpStream(const HttpStream &) = delete;
132 HttpStream(HttpStream &&) = delete;
133 HttpStream &operator=(const HttpStream &) = delete;
134 HttpStream &operator=(HttpStream &&) = delete;
135
139 HttpClientConnection &GetConnection() const noexcept;
140
144 virtual int GetResponseStatusCode() const noexcept = 0;
145
155 void UpdateWindow(std::size_t incrementSize) noexcept;
156
157 protected:
158 aws_http_stream *m_stream;
159 std::shared_ptr<HttpClientConnection> m_connection;
160 HttpStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
161
162 private:
163 OnIncomingHeaders m_onIncomingHeaders;
164 OnIncomingHeadersBlockDone m_onIncomingHeadersBlockDone;
165 OnIncomingBody m_onIncomingBody;
166 OnStreamComplete m_onStreamComplete;
167
168 static int s_onIncomingHeaders(
169 struct aws_http_stream *stream,
170 enum aws_http_header_block headerBlock,
171 const struct aws_http_header *headerArray,
172 size_t numHeaders,
173 void *userData) noexcept;
174 static int s_onIncomingHeaderBlockDone(
175 struct aws_http_stream *stream,
176 enum aws_http_header_block headerBlock,
177 void *userData) noexcept;
178 static int s_onIncomingBody(
179 struct aws_http_stream *stream,
180 const struct aws_byte_cursor *data,
181 void *userData) noexcept;
182 static void s_onStreamComplete(struct aws_http_stream *stream, int errorCode, void *userData) noexcept;
183
184 friend class HttpClientConnection;
185 };
186
187 struct ClientStreamCallbackData
188 {
189 ClientStreamCallbackData() : allocator(nullptr), stream(nullptr) {}
190 Allocator *allocator;
191 std::shared_ptr<HttpStream> stream;
192 };
193
197 class AWS_CRT_CPP_API HttpClientStream final : public HttpStream
198 {
199 public:
200 ~HttpClientStream();
201 HttpClientStream(const HttpClientStream &) = delete;
202 HttpClientStream(HttpClientStream &&) = delete;
203 HttpClientStream &operator=(const HttpClientStream &) = delete;
204 HttpClientStream &operator=(HttpClientStream &&) = delete;
205
210 virtual int GetResponseStatusCode() const noexcept override;
211
217 bool Activate() noexcept;
218
219 private:
220 HttpClientStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
221
222 ClientStreamCallbackData m_callbackData;
223 friend class HttpClientConnection;
224 };
225
232 enum class AwsHttpProxyAuthenticationType
233 {
234 None,
235 Basic,
236 };
237
242 enum class AwsHttpProxyConnectionType
243 {
251 Legacy = AWS_HPCT_HTTP_LEGACY,
252
257 Forwarding = AWS_HPCT_HTTP_FORWARD,
258
263 Tunneling = AWS_HPCT_HTTP_TUNNEL,
264 };
265
269 class AWS_CRT_CPP_API HttpClientConnectionProxyOptions
270 {
271 public:
272 HttpClientConnectionProxyOptions();
273 HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs) = default;
274 HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs) = default;
275
276 HttpClientConnectionProxyOptions &operator=(const HttpClientConnectionProxyOptions &rhs) = default;
277 HttpClientConnectionProxyOptions &operator=(HttpClientConnectionProxyOptions &&rhs) = default;
278
279 ~HttpClientConnectionProxyOptions() = default;
280
289 void InitializeRawProxyOptions(struct aws_http_proxy_options &raw_options) const;
290
295 String HostName;
296
301 uint16_t Port;
302
307 Optional<Io::TlsConnectionOptions> TlsOptions;
308
312 AwsHttpProxyConnectionType ProxyConnectionType;
313
318 std::shared_ptr<HttpProxyStrategy> ProxyStrategy;
319
328 AwsHttpProxyAuthenticationType AuthType;
329
334 String BasicAuthUsername;
335
340 String BasicAuthPassword;
341 };
342
346 class AWS_CRT_CPP_API HttpClientConnectionOptions
347 {
348 public:
349 HttpClientConnectionOptions();
350 HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs) = default;
351 HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs) = default;
352
353 ~HttpClientConnectionOptions() = default;
354
355 HttpClientConnectionOptions &operator=(const HttpClientConnectionOptions &rhs) = default;
356 HttpClientConnectionOptions &operator=(HttpClientConnectionOptions &&rhs) = default;
357
362 Io::ClientBootstrap *Bootstrap;
363
367 size_t InitialWindowSize;
368
374 OnConnectionSetup OnConnectionSetupCallback;
375
381 OnConnectionShutdown OnConnectionShutdownCallback;
382
387 String HostName;
388
393 uint16_t Port;
394
399 Io::SocketOptions SocketOptions;
400
405 Optional<Io::TlsConnectionOptions> TlsOptions;
406
411 Optional<HttpClientConnectionProxyOptions> ProxyOptions;
412
420 bool ManualWindowManagement;
421 };
422
423 enum class HttpVersion
424 {
425 Unknown = AWS_HTTP_VERSION_UNKNOWN,
426 Http1_0 = AWS_HTTP_VERSION_1_0,
427 Http1_1 = AWS_HTTP_VERSION_1_1,
428 Http2 = AWS_HTTP_VERSION_2,
429 };
430
434 class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
435 {
436 public:
437 virtual ~HttpClientConnection() = default;
438 HttpClientConnection(const HttpClientConnection &) = delete;
439 HttpClientConnection(HttpClientConnection &&) = delete;
440 HttpClientConnection &operator=(const HttpClientConnection &) = delete;
441 HttpClientConnection &operator=(HttpClientConnection &&) = delete;
442
455 std::shared_ptr<HttpClientStream> NewClientStream(const HttpRequestOptions &requestOptions) noexcept;
456
460 bool IsOpen() const noexcept;
461
469 void Close() noexcept;
470
474 HttpVersion GetVersion() noexcept;
475
479 int LastError() const noexcept { return m_lastError; }
480
489 static bool CreateConnection(
490 const HttpClientConnectionOptions &connectionOptions,
491 Allocator *allocator) noexcept;
492
493 protected:
494 HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
495 aws_http_connection *m_connection;
496
497 private:
498 Allocator *m_allocator;
499 int m_lastError;
500
501 static void s_onClientConnectionSetup(
502 struct aws_http_connection *connection,
503 int error_code,
504 void *user_data) noexcept;
505 static void s_onClientConnectionShutdown(
506 struct aws_http_connection *connection,
507 int error_code,
508 void *user_data) noexcept;
509 };
510
511 } // namespace Http
512 } // namespace Crt
513} // namespace Aws
Bootstrap.h
SocketOptions.h
TlsOptions.h
Types.h
Aws::Crt::Http::HttpClientConnection
Definition: HttpConnection.h:435
Aws::Crt::Http::HttpClientConnection::~HttpClientConnection
virtual ~HttpClientConnection()=default
Aws::Crt::Http::HttpClientConnection::operator=
HttpClientConnection & operator=(HttpClientConnection &&)=delete
Aws::Crt::Http::HttpClientConnection::m_connection
aws_http_connection * m_connection
Definition: HttpConnection.h:495
Aws::Crt::Http::HttpClientConnection::operator=
HttpClientConnection & operator=(const HttpClientConnection &)=delete
Aws::Crt::Http::HttpClientConnection::HttpClientConnection
HttpClientConnection(const HttpClientConnection &)=delete
Aws::Crt::Http::HttpClientConnection::HttpClientConnection
HttpClientConnection(HttpClientConnection &&)=delete
Aws::Crt::Http::HttpClientConnectionOptions
Definition: HttpConnection.h:347
Aws::Crt::Http::HttpClientConnectionOptions::ProxyOptions
Optional< HttpClientConnectionProxyOptions > ProxyOptions
Definition: HttpConnection.h:411
Aws::Crt::Http::HttpClientConnectionOptions::HttpClientConnectionOptions
HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs)=default
Aws::Crt::Http::HttpClientConnectionOptions::operator=
HttpClientConnectionOptions & operator=(const HttpClientConnectionOptions &rhs)=default
Aws::Crt::Http::HttpClientConnectionOptions::Port
uint16_t Port
Definition: HttpConnection.h:393
Aws::Crt::Http::HttpClientConnectionOptions::TlsOptions
Optional< Io::TlsConnectionOptions > TlsOptions
Definition: HttpConnection.h:405
Aws::Crt::Http::HttpClientConnectionOptions::InitialWindowSize
size_t InitialWindowSize
Definition: HttpConnection.h:367
Aws::Crt::Http::HttpClientConnectionOptions::HttpClientConnectionOptions
HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs)=default
Aws::Crt::Http::HttpClientConnectionOptions::OnConnectionSetupCallback
OnConnectionSetup OnConnectionSetupCallback
Definition: HttpConnection.h:374
Aws::Crt::Http::HttpClientConnectionOptions::SocketOptions
Io::SocketOptions SocketOptions
Definition: HttpConnection.h:399
Aws::Crt::Http::HttpClientConnectionOptions::HostName
String HostName
Definition: HttpConnection.h:387
Aws::Crt::Http::HttpClientConnectionOptions::OnConnectionShutdownCallback
OnConnectionShutdown OnConnectionShutdownCallback
Definition: HttpConnection.h:381
Aws::Crt::Http::HttpClientConnectionOptions::Bootstrap
Io::ClientBootstrap * Bootstrap
Definition: HttpConnection.h:362
Aws::Crt::Http::HttpClientConnectionOptions::~HttpClientConnectionOptions
~HttpClientConnectionOptions()=default
Aws::Crt::Http::HttpClientConnectionOptions::operator=
HttpClientConnectionOptions & operator=(HttpClientConnectionOptions &&rhs)=default
Aws::Crt::Http::HttpClientConnectionOptions::ManualWindowManagement
bool ManualWindowManagement
Definition: HttpConnection.h:420
Aws::Crt::Http::HttpClientConnectionProxyOptions
Definition: HttpConnection.h:270
Aws::Crt::Http::HttpClientConnectionProxyOptions::operator=
HttpClientConnectionProxyOptions & operator=(const HttpClientConnectionProxyOptions &rhs)=default
Aws::Crt::Http::HttpClientConnectionProxyOptions::ProxyConnectionType
AwsHttpProxyConnectionType ProxyConnectionType
Definition: HttpConnection.h:312
Aws::Crt::Http::HttpClientConnectionProxyOptions::~HttpClientConnectionProxyOptions
~HttpClientConnectionProxyOptions()=default
Aws::Crt::Http::HttpClientConnectionProxyOptions::HttpClientConnectionProxyOptions
HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs)=default
Aws::Crt::Http::HttpClientConnectionProxyOptions::HttpClientConnectionProxyOptions
HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs)=default
Aws::Crt::Http::HttpClientConnectionProxyOptions::TlsOptions
Optional< Io::TlsConnectionOptions > TlsOptions
Definition: HttpConnection.h:307
Aws::Crt::Http::HttpClientConnectionProxyOptions::BasicAuthPassword
String BasicAuthPassword
Definition: HttpConnection.h:340
Aws::Crt::Http::HttpClientConnectionProxyOptions::ProxyStrategy
std::shared_ptr< HttpProxyStrategy > ProxyStrategy
Definition: HttpConnection.h:318
Aws::Crt::Http::HttpClientConnectionProxyOptions::AuthType
AwsHttpProxyAuthenticationType AuthType
Definition: HttpConnection.h:328
Aws::Crt::Http::HttpClientConnectionProxyOptions::BasicAuthUsername
String BasicAuthUsername
Definition: HttpConnection.h:334
Aws::Crt::Http::HttpClientConnectionProxyOptions::operator=
HttpClientConnectionProxyOptions & operator=(HttpClientConnectionProxyOptions &&rhs)=default
Aws::Crt::Http::HttpClientConnectionProxyOptions::Port
uint16_t Port
Definition: HttpConnection.h:301
Aws::Crt::Http::HttpClientConnectionProxyOptions::HostName
String HostName
Definition: HttpConnection.h:295
Aws::Crt::Http::HttpClientStream
Definition: HttpConnection.h:198
Aws::Crt::Http::HttpClientStream::operator=
HttpClientStream & operator=(const HttpClientStream &)=delete
Aws::Crt::Http::HttpClientStream::operator=
HttpClientStream & operator=(HttpClientStream &&)=delete
Aws::Crt::Http::HttpClientStream::HttpClientStream
HttpClientStream(const HttpClientStream &)=delete
Aws::Crt::Http::HttpClientStream::HttpClientStream
HttpClientStream(HttpClientStream &&)=delete
Aws::Crt::Http::HttpRequest
Definition: HttpRequestResponse.h:106
Aws::Crt::Http::HttpStream
Definition: HttpConnection.h:128
Aws::Crt::Http::HttpStream::HttpStream
HttpStream(const HttpStream &)=delete
Aws::Crt::Http::HttpStream::operator=
HttpStream & operator=(const HttpStream &)=delete
Aws::Crt::Http::HttpStream::HttpStream
HttpStream(HttpStream &&)=delete
Aws::Crt::Http::HttpStream::operator=
HttpStream & operator=(HttpStream &&)=delete
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::Io::SocketOptions
Definition: SocketOptions.h:48
Aws::Crt::Optional
Definition: Optional.h:17
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Http::HttpHeader
aws_http_header HttpHeader
Definition: HttpConnection.h:34
Aws::Crt::Http::OnConnectionShutdown
std::function< void(HttpClientConnection &connection, int errorCode)> OnConnectionShutdown
Definition: HttpConnection.h:53
Aws::Crt::Http::AwsHttpProxyConnectionType
AwsHttpProxyConnectionType
Definition: HttpConnection.h:243
Aws::Crt::Http::AwsHttpProxyConnectionType::Legacy
@ Legacy
Aws::Crt::Http::AwsHttpProxyConnectionType::Forwarding
@ Forwarding
Aws::Crt::Http::AwsHttpProxyConnectionType::Tunneling
@ Tunneling
Aws::Crt::Http::OnStreamComplete
std::function< void(HttpStream &stream, int errorCode)> OnStreamComplete
Definition: HttpConnection.h:94
Aws::Crt::Http::OnIncomingHeadersBlockDone
std::function< void(HttpStream &stream, enum aws_http_header_block block)> OnIncomingHeadersBlockDone
Definition: HttpConnection.h:76
Aws::Crt::Http::OnIncomingHeaders
std::function< void(HttpStream &stream, enum aws_http_header_block headerBlock, const HttpHeader *headersArray, std::size_t headersCount)> OnIncomingHeaders
Definition: HttpConnection.h:67
Aws::Crt::Http::OnIncomingBody
std::function< void(HttpStream &stream, const ByteCursor &data)> OnIncomingBody
Definition: HttpConnection.h:84
Aws::Crt::Http::OnConnectionSetup
std::function< void(const std::shared_ptr< HttpClientConnection > &connection, int errorCode)> OnConnectionSetup
Definition: HttpConnection.h:43
Aws::Crt::Http::AwsHttpProxyAuthenticationType
AwsHttpProxyAuthenticationType
Definition: HttpConnection.h:233
Aws::Crt::Http::AwsHttpProxyAuthenticationType::Basic
@ Basic
Aws::Crt::Http::HttpVersion
HttpVersion
Definition: HttpConnection.h:424
Aws::Crt::Http::HttpVersion::Http1_1
@ Http1_1
Aws::Crt::Http::HttpVersion::Unknown
@ Unknown
Aws::Crt::Http::HttpVersion::Http1_0
@ Http1_0
Aws::Crt::Http::HttpVersion::Http2
@ Http2
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:33
Aws::Crt::LogLevel::None
@ None
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
Aws::Crt::LastError
AWS_CRT_CPP_API int LastError() noexcept
Definition: Api.cpp:315
Aws
Definition: Api.h:17
std
Definition: StringView.h:851
Aws::Crt::Http::ClientStreamCallbackData
Definition: HttpConnection.h:188
Aws::Crt::Http::ClientStreamCallbackData::ClientStreamCallbackData
ClientStreamCallbackData()
Definition: HttpConnection.h:189
Aws::Crt::Http::ClientStreamCallbackData::allocator
Allocator * allocator
Definition: HttpConnection.h:190
Aws::Crt::Http::ClientStreamCallbackData::stream
std::shared_ptr< HttpStream > stream
Definition: HttpConnection.h:191
Aws::Crt::Http::HttpRequestOptions
Definition: HttpConnection.h:100
Aws::Crt::Http::HttpRequestOptions::onStreamComplete
OnStreamComplete onStreamComplete
Definition: HttpConnection.h:120
Aws::Crt::Http::HttpRequestOptions::onIncomingHeaders
OnIncomingHeaders onIncomingHeaders
Definition: HttpConnection.h:109
Aws::Crt::Http::HttpRequestOptions::onIncomingHeadersBlockDone
OnIncomingHeadersBlockDone onIncomingHeadersBlockDone
Definition: HttpConnection.h:110
Aws::Crt::Http::HttpRequestOptions::request
HttpRequest * request
Definition: HttpConnection.h:104
Aws::Crt::Http::HttpRequestOptions::onIncomingBody
OnIncomingBody onIncomingBody
Definition: HttpConnection.h:115