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 }
27
28 namespace Http
29 {
30 class HttpClientConnection;
31 class HttpStream;
32 class HttpClientStream;
33 class HttpRequest;
34 class HttpProxyStrategy;
35 using HttpHeader = aws_http_header;
36
44 std::function<void(const std::shared_ptr<HttpClientConnection> &connection, int errorCode)>;
45
54 using OnConnectionShutdown = std::function<void(HttpClientConnection &connection, int errorCode)>;
55
64 using OnIncomingHeaders = std::function<void(
65 HttpStream &stream,
66 enum aws_http_header_block headerBlock,
67 const HttpHeader *headersArray,
68 std::size_t headersCount)>;
69
77 std::function<void(HttpStream &stream, enum aws_http_header_block block)>;
78
85 using OnIncomingBody = std::function<void(HttpStream &stream, const ByteCursor &data)>;
86
95 using OnStreamComplete = std::function<void(HttpStream &stream, int errorCode)>;
96
144
149 class AWS_CRT_CPP_API HttpStream : public std::enable_shared_from_this<HttpStream>
150 {
151 public:
152 virtual ~HttpStream();
153 HttpStream(const HttpStream &) = delete;
154 HttpStream(HttpStream &&) = delete;
155 HttpStream &operator=(const HttpStream &) = delete;
157
161 HttpClientConnection &GetConnection() const noexcept;
162
166 virtual int GetResponseStatusCode() const noexcept = 0;
167
177 void UpdateWindow(std::size_t incrementSize) noexcept;
178
179 protected:
180 aws_http_stream *m_stream;
181 std::shared_ptr<HttpClientConnection> m_connection;
182 HttpStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
183
184 private:
185 OnIncomingHeaders m_onIncomingHeaders;
186 OnIncomingHeadersBlockDone m_onIncomingHeadersBlockDone;
187 OnIncomingBody m_onIncomingBody;
188 OnStreamComplete m_onStreamComplete;
189
190 static int s_onIncomingHeaders(
191 struct aws_http_stream *stream,
192 enum aws_http_header_block headerBlock,
193 const struct aws_http_header *headerArray,
194 size_t numHeaders,
195 void *userData) noexcept;
196 static int s_onIncomingHeaderBlockDone(
197 struct aws_http_stream *stream,
198 enum aws_http_header_block headerBlock,
199 void *userData) noexcept;
200 static int s_onIncomingBody(
201 struct aws_http_stream *stream,
202 const struct aws_byte_cursor *data,
203 void *userData) noexcept;
204 static void s_onStreamComplete(struct aws_http_stream *stream, int errorCode, void *userData) noexcept;
205
207 };
208
210 {
211 ClientStreamCallbackData() : allocator(nullptr), stream(nullptr) {}
213 std::shared_ptr<HttpStream> stream;
214 };
215
216 using OnWriteDataComplete = std::function<void(std::shared_ptr<HttpStream> &stream, int errorCode)>;
217
222 {
223 public:
229
234 virtual int GetResponseStatusCode() const noexcept override;
235
241 bool Activate() noexcept;
242
243 int WriteData(
244 std::shared_ptr<Aws::Crt::Io::InputStream> stream,
245 const OnWriteDataComplete &onComplete,
246 bool endStream = false) noexcept;
247
248 private:
249 HttpClientStream(const std::shared_ptr<HttpClientConnection> &connection) noexcept;
250
251 ClientStreamCallbackData m_callbackData;
253 };
254
262 {
263 None,
264 Basic,
265 };
266
272 {
280 Legacy = AWS_HPCT_HTTP_LEGACY,
281
286 Forwarding = AWS_HPCT_HTTP_FORWARD,
287
292 Tunneling = AWS_HPCT_HTTP_TUNNEL,
293 };
294
371
376 {
381 Disabled = AWS_HPEV_DISABLE,
390 Enabled = AWS_HPEV_ENABLE,
391 };
392
397 {
398 public:
402
405
407
416 void InitializeRawProxyOptions(struct proxy_env_var_settings &raw_options) const;
417
422
430
436 };
437
518
519 enum class HttpVersion
520 {
521 Unknown = AWS_HTTP_VERSION_UNKNOWN,
522 Http1_0 = AWS_HTTP_VERSION_1_0,
523 Http1_1 = AWS_HTTP_VERSION_1_1,
524 Http2 = AWS_HTTP_VERSION_2,
525 };
526
530 class AWS_CRT_CPP_API HttpClientConnection : public std::enable_shared_from_this<HttpClientConnection>
531 {
532 public:
533 virtual ~HttpClientConnection() = default;
538
551 std::shared_ptr<HttpClientStream> NewClientStream(const HttpRequestOptions &requestOptions) noexcept;
552
556 bool IsOpen() const noexcept;
557
565 void Close() noexcept;
566
570 HttpVersion GetVersion() noexcept;
571
575 int LastError() const noexcept { return m_lastError; }
576
585 static bool CreateConnection(
586 const HttpClientConnectionOptions &connectionOptions,
587 Allocator *allocator) noexcept;
588
589 protected:
590 HttpClientConnection(aws_http_connection *m_connection, Allocator *allocator) noexcept;
591 aws_http_connection *m_connection;
592
593 private:
594 Allocator *m_allocator;
595 int m_lastError;
596
597 static void s_onClientConnectionSetup(
598 struct aws_http_connection *connection,
599 int error_code,
600 void *user_data) noexcept;
601 static void s_onClientConnectionShutdown(
602 struct aws_http_connection *connection,
603 int error_code,
604 void *user_data) noexcept;
605 };
606
607 } // namespace Http
608 } // namespace Crt
609} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition HttpConnection.h:531
HttpClientConnection & operator=(HttpClientConnection &&)=delete
aws_http_connection * m_connection
Definition HttpConnection.h:591
HttpClientConnection & operator=(const HttpClientConnection &)=delete
HttpClientConnection(const HttpClientConnection &)=delete
HttpClientConnection(HttpClientConnection &&)=delete
Definition HttpConnection.h:442
Optional< HttpClientConnectionProxyOptions > ProxyOptions
Definition HttpConnection.h:507
HttpClientConnectionOptions(HttpClientConnectionOptions &&rhs)=default
HttpClientConnectionOptions & operator=(const HttpClientConnectionOptions &rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:501
size_t InitialWindowSize
Definition HttpConnection.h:463
HttpClientConnectionOptions(const HttpClientConnectionOptions &rhs)=default
OnConnectionSetup OnConnectionSetupCallback
Definition HttpConnection.h:470
Io::SocketOptions SocketOptions
Definition HttpConnection.h:495
String HostName
Definition HttpConnection.h:483
OnConnectionShutdown OnConnectionShutdownCallback
Definition HttpConnection.h:477
Io::ClientBootstrap * Bootstrap
Definition HttpConnection.h:458
HttpClientConnectionOptions & operator=(HttpClientConnectionOptions &&rhs)=default
bool ManualWindowManagement
Definition HttpConnection.h:516
uint32_t Port
Definition HttpConnection.h:489
HttpClientConnectionProxyOptions & operator=(const HttpClientConnectionProxyOptions &rhs)=default
AwsHttpProxyConnectionType ProxyConnectionType
Definition HttpConnection.h:341
HttpClientConnectionProxyOptions(const HttpClientConnectionProxyOptions &rhs)=default
HttpClientConnectionProxyOptions(HttpClientConnectionProxyOptions &&rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:336
String BasicAuthPassword
Definition HttpConnection.h:369
uint32_t Port
Definition HttpConnection.h:330
std::shared_ptr< HttpProxyStrategy > ProxyStrategy
Definition HttpConnection.h:347
AwsHttpProxyAuthenticationType AuthType
Definition HttpConnection.h:357
String BasicAuthUsername
Definition HttpConnection.h:363
HttpClientConnectionProxyOptions & operator=(HttpClientConnectionProxyOptions &&rhs)=default
String HostName
Definition HttpConnection.h:324
Definition HttpConnection.h:222
HttpClientStream & operator=(const HttpClientStream &)=delete
HttpClientStream & operator=(HttpClientStream &&)=delete
HttpClientStream(const HttpClientStream &)=delete
HttpClientStream(HttpClientStream &&)=delete
Definition HttpRequestResponse.h:110
Definition HttpConnection.h:150
HttpStream(const HttpStream &)=delete
HttpStream & operator=(const HttpStream &)=delete
HttpStream(HttpStream &&)=delete
HttpStream & operator=(HttpStream &&)=delete
Definition HttpConnection.h:397
ProxyEnvVarOptions & operator=(const ProxyEnvVarOptions &rhs)=default
Optional< Io::TlsConnectionOptions > TlsOptions
Definition HttpConnection.h:435
ProxyEnvVarOptions & operator=(ProxyEnvVarOptions &&rhs)=default
ProxyEnvVarOptions(const ProxyEnvVarOptions &rhs)=default
ProxyEnvVarType proxyEnvVarType
Definition HttpConnection.h:421
ProxyEnvVarOptions(ProxyEnvVarOptions &&rhs)=default
AwsHttpProxyConnectionType connectionType
Definition HttpConnection.h:429
Definition Bootstrap.h:35
Definition SocketOptions.h:48
Definition Optional.h:19
aws_http_header HttpHeader
Definition HttpConnection.h:35
std::function< void(HttpClientConnection &connection, int errorCode)> OnConnectionShutdown
Definition HttpConnection.h:54
AwsHttpProxyConnectionType
Definition HttpConnection.h:272
std::function< void(HttpStream &stream, int errorCode)> OnStreamComplete
Definition HttpConnection.h:95
ProxyEnvVarType
Definition HttpConnection.h:376
std::function< void(HttpStream &stream, enum aws_http_header_block block)> OnIncomingHeadersBlockDone
Definition HttpConnection.h:77
std::function< void(std::shared_ptr< HttpStream > &stream, int errorCode)> OnWriteDataComplete
Definition HttpConnection.h:216
std::function< void(HttpStream &stream, enum aws_http_header_block headerBlock, const HttpHeader *headersArray, std::size_t headersCount)> OnIncomingHeaders
Definition HttpConnection.h:68
std::function< void(HttpStream &stream, const ByteCursor &data)> OnIncomingBody
Definition HttpConnection.h:85
std::function< void(const std::shared_ptr< HttpClientConnection > &connection, int errorCode)> OnConnectionSetup
Definition HttpConnection.h:44
AwsHttpProxyAuthenticationType
Definition HttpConnection.h:262
HttpVersion
Definition HttpConnection.h:520
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:210
ClientStreamCallbackData()
Definition HttpConnection.h:211
Allocator * allocator
Definition HttpConnection.h:212
std::shared_ptr< HttpStream > stream
Definition HttpConnection.h:213
Definition HttpConnection.h:101
OnStreamComplete onStreamComplete
Definition HttpConnection.h:121
OnIncomingHeaders onIncomingHeaders
Definition HttpConnection.h:110
OnIncomingHeadersBlockDone onIncomingHeadersBlockDone
Definition HttpConnection.h:111
HttpRequest * request
Definition HttpConnection.h:105
OnIncomingBody onIncomingBody
Definition HttpConnection.h:116