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>
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
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;
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
185 };
186
188 {
189 ClientStreamCallbackData() : allocator(nullptr), stream(nullptr) {}
191 std::shared_ptr<HttpStream> stream;
192 };
193
198 {
199 public:
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;
224 };
225
233 {
234 None,
235 Basic,
236 };
237
243 {
251 Legacy = AWS_HPCT_HTTP_LEGACY,
252
257 Forwarding = AWS_HPCT_HTTP_FORWARD,
258
263 Tunneling = AWS_HPCT_HTTP_TUNNEL,
264 };
265
342
423
424 enum class HttpVersion
425 {
426 Unknown = AWS_HTTP_VERSION_UNKNOWN,
427 Http1_0 = AWS_HTTP_VERSION_1_0,
428 Http1_1 = AWS_HTTP_VERSION_1_1,
429 Http2 = AWS_HTTP_VERSION_2,
430 };
431
435 class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
436 {
437 public:
438 virtual ~HttpClientConnection() = default;
443
456 std::shared_ptr<HttpClientStream> NewClientStream(const HttpRequestOptions &requestOptions) noexcept;
457
461 bool IsOpen() const noexcept;
462
470 void Close() noexcept;
471
475 HttpVersion GetVersion() noexcept;
476
480 int LastError() const noexcept { return m_lastError; }
481
490 static bool CreateConnection(
491 const HttpClientConnectionOptions &connectionOptions,
492 Allocator *allocator) noexcept;
493
494 protected:
495 HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
496 aws_http_connection *m_connection;
497
498 private:
499 Allocator *m_allocator;
500 int m_lastError;
501
502 static void s_onClientConnectionSetup(
503 struct aws_http_connection *connection,
504 int error_code,
505 void *user_data) noexcept;
506 static void s_onClientConnectionShutdown(
507 struct aws_http_connection *connection,
508 int error_code,
509 void *user_data) noexcept;
510 };
511
512 } // namespace Http
513 } // namespace Crt
514} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition HttpConnection.h:436
HttpClientConnection & operator=(HttpClientConnection &&)=delete
aws_http_connection * m_connection
Definition HttpConnection.h:496
HttpClientConnection & operator=(const HttpClientConnection &)=delete
HttpClientConnection(const HttpClientConnection &)=delete
HttpClientConnection(HttpClientConnection &&)=delete
Definition HttpConnection.h:347
Optional< HttpClientConnectionProxyOptions > ProxyOptions
Definition HttpConnection.h:412
HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs)=default
HttpClientConnectionOptions & operator=(const HttpClientConnectionOptions &rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:406
size_t InitialWindowSize
Definition HttpConnection.h:368
HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs)=default
OnConnectionSetup OnConnectionSetupCallback
Definition HttpConnection.h:375
Io::SocketOptions SocketOptions
Definition HttpConnection.h:400
String HostName
Definition HttpConnection.h:388
OnConnectionShutdown OnConnectionShutdownCallback
Definition HttpConnection.h:382
Io::ClientBootstrap * Bootstrap
Definition HttpConnection.h:363
HttpClientConnectionOptions & operator=(HttpClientConnectionOptions &&rhs)=default
bool ManualWindowManagement
Definition HttpConnection.h:421
uint32_t Port
Definition HttpConnection.h:394
HttpClientConnectionProxyOptions & operator=(const HttpClientConnectionProxyOptions &rhs)=default
AwsHttpProxyConnectionType ProxyConnectionType
Definition HttpConnection.h:312
HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs)=default
HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:307
String BasicAuthPassword
Definition HttpConnection.h:340
uint32_t Port
Definition HttpConnection.h:301
std::shared_ptr< HttpProxyStrategy > ProxyStrategy
Definition HttpConnection.h:318
AwsHttpProxyAuthenticationType AuthType
Definition HttpConnection.h:328
String BasicAuthUsername
Definition HttpConnection.h:334
HttpClientConnectionProxyOptions & operator=(HttpClientConnectionProxyOptions &&rhs)=default
String HostName
Definition HttpConnection.h:295
Definition HttpConnection.h:198
HttpClientStream & operator=(const HttpClientStream &)=delete
HttpClientStream & operator=(HttpClientStream &&)=delete
HttpClientStream(const HttpClientStream &)=delete
HttpClientStream(HttpClientStream &&)=delete
Definition HttpRequestResponse.h:110
Definition HttpConnection.h:128
HttpStream(const HttpStream &)=delete
HttpStream & operator=(const HttpStream &)=delete
HttpStream(HttpStream &&)=delete
HttpStream & operator=(HttpStream &&)=delete
Definition Bootstrap.h:35
Definition SocketOptions.h:48
Definition Optional.h:19
aws_http_header HttpHeader
Definition HttpConnection.h:34
std::function< void(HttpClientConnection &connection, int errorCode)> OnConnectionShutdown
Definition HttpConnection.h:53
AwsHttpProxyConnectionType
Definition HttpConnection.h:243
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:233
HttpVersion
Definition HttpConnection.h:425
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:188
ClientStreamCallbackData()
Definition HttpConnection.h:189
Allocator * allocator
Definition HttpConnection.h:190
std::shared_ptr< HttpStream > stream
Definition HttpConnection.h:191
Definition HttpConnection.h:100
OnStreamComplete onStreamComplete
Definition HttpConnection.h:120
OnIncomingHeaders onIncomingHeaders
Definition HttpConnection.h:109
OnIncomingHeadersBlockDone onIncomingHeadersBlockDone
Definition HttpConnection.h:110
HttpRequest * request
Definition HttpConnection.h:104
OnIncomingBody onIncomingBody
Definition HttpConnection.h:115