18
18
19
19
#include < aws/crt/Types.h>
20
20
#include < aws/crt/io/Bootstrap.h>
21
+ #include < aws/crt/io/SocketOptions.h>
21
22
#include < aws/crt/io/TlsOptions.h>
22
23
23
24
#include < functional>
@@ -99,7 +100,7 @@ namespace Aws
99
100
/* *
100
101
* POD structure used for setting up an Http Request
101
102
*/
102
- struct HttpRequestOptions
103
+ struct AWS_CRT_CPP_API HttpRequestOptions
103
104
{
104
105
105
106
HttpRequest *request;
@@ -181,7 +182,7 @@ namespace Aws
181
182
friend class HttpClientConnection ;
182
183
};
183
184
184
- class HttpClientStream final : public HttpStream
185
+ class AWS_CRT_CPP_API HttpClientStream final : public HttpStream
185
186
{
186
187
public:
187
188
~HttpClientStream () = default ;
@@ -202,49 +203,251 @@ namespace Aws
202
203
friend class HttpClientConnection ;
203
204
};
204
205
205
- struct HttpClientConnectionOptions
206
+ /* *
207
+ * Mirror of the aws_http_proxy_authentication_type C enum - designates what kind of
208
+ * authentication, if any, to use when connecting to a proxy server
209
+ */
210
+ enum class AwsHttpProxyAuthenticationType
211
+ {
212
+ None = AWS_HPAT_NONE,
213
+ Basic = AWS_HPAT_BASIC,
214
+ };
215
+
216
+ /* *
217
+ * Configuration structure that holds all proxy-related http connection options
218
+ */
219
+ class AWS_CRT_CPP_API HttpClientConnectionProxyOptions
206
220
{
221
+ public:
222
+ HttpClientConnectionProxyOptions ();
223
+ HttpClientConnectionProxyOptions (const HttpClientConnectionProxyOptions &rhs) = default ;
224
+ HttpClientConnectionProxyOptions (HttpClientConnectionProxyOptions &&rhs) = default ;
225
+
226
+ HttpClientConnectionProxyOptions &operator =(const HttpClientConnectionProxyOptions &rhs) = default ;
227
+ HttpClientConnectionProxyOptions &operator =(HttpClientConnectionProxyOptions &&rhs) = default ;
228
+
229
+ ~HttpClientConnectionProxyOptions () = default ;
230
+
231
+ /* *
232
+ * Sets the name of the proxy server to connect through.
233
+ * This value must be set.
234
+ */
235
+ void SetHostName (const String &hostName) noexcept { m_hostName = hostName; }
236
+
237
+ /* *
238
+ * Returns the name of the proxy server to connect through.
239
+ */
240
+ const String &GetHostName () const noexcept { return m_hostName; }
241
+
242
+ /* *
243
+ * Sets the port of the proxy server to connect to.
244
+ * This value must be set.
245
+ */
246
+ void SetPort (uint16_t port) noexcept { m_port = port; }
247
+
248
+ /* *
249
+ * Gets the port of the proxy server to connect to.
250
+ */
251
+ uint16_t GetPort () const noexcept { return m_port; }
252
+
253
+ /* *
254
+ * Sets the TLS options for the proxy connection.
255
+ */
256
+ void SetTlsOptions (const Io::TlsConnectionOptions &options) noexcept { m_tlsOptions = options; }
257
+
258
+ /* *
259
+ * Gets the TLS options for the proxy connection.
260
+ */
261
+ const Io::TlsConnectionOptions *GetTlsOptions () const noexcept
262
+ {
263
+ return m_tlsOptions.has_value () ? &m_tlsOptions.value () : nullptr ;
264
+ }
265
+
266
+ /* *
267
+ * Sets what kind of authentication approach to use when connecting to the proxy
268
+ */
269
+ void SetAuthenticationType (AwsHttpProxyAuthenticationType authType) noexcept { m_authType = authType; }
270
+
271
+ /* *
272
+ * Gets what kind of authentication approach to use when connecting to the proxy
273
+ */
274
+ AwsHttpProxyAuthenticationType GetAuthenticationType () const noexcept { return m_authType; }
275
+
276
+ /* *
277
+ * Sets the username to use when connecting to the proxy via basic authentication
278
+ */
279
+ void SetBasicAuthUsername (const String &username) noexcept { m_basicAuthUsername = username; }
280
+
281
+ /* *
282
+ * Gets the username to use when connecting to the proxy via basic authentication
283
+ */
284
+ const String &GetBasicAuthUsername () const noexcept { return m_basicAuthUsername; }
285
+
286
+ /* *
287
+ * Sets the password to use when connecting to the proxy via basic authentication
288
+ */
289
+ void SetBasicAuthPassword (const String &password) noexcept { m_basicAuthPassword = password; }
290
+
291
+ /* *
292
+ * Gets the password to use when connecting to the proxy via basic authentication
293
+ */
294
+ const String &GetBasicAuthPassword () const noexcept { return m_basicAuthPassword; }
295
+
296
+ private:
297
+ String m_hostName;
298
+ uint16_t m_port;
299
+ Optional<Io::TlsConnectionOptions> m_tlsOptions;
300
+ AwsHttpProxyAuthenticationType m_authType;
301
+ String m_basicAuthUsername;
302
+ String m_basicAuthPassword;
303
+ };
304
+
305
+ /* *
306
+ * Configuration structure holding all options relating to http connection establishment
307
+ */
308
+ class AWS_CRT_CPP_API HttpClientConnectionOptions
309
+ {
310
+ public:
207
311
HttpClientConnectionOptions ();
208
- Allocator *allocator;
312
+ HttpClientConnectionOptions (const HttpClientConnectionOptions &rhs) = default ;
313
+ HttpClientConnectionOptions (HttpClientConnectionOptions &&rhs) = default ;
314
+
315
+ ~HttpClientConnectionOptions () = default ;
316
+
317
+ HttpClientConnectionOptions &operator =(const HttpClientConnectionOptions &rhs) = default ;
318
+ HttpClientConnectionOptions &operator =(HttpClientConnectionOptions &&rhs) = default ;
209
319
210
320
/* *
211
- * Client bootstrap to use for setting up and tearing down connections.
321
+ * Sets the client bootstrap to use for setting up and tearing down connections.
322
+ * This value must be set.
212
323
*/
213
- Io::ClientBootstrap *bootstrap;
324
+ void SetBootstrap (Io::ClientBootstrap *bootstrap) noexcept { m_bootstrap = bootstrap; }
325
+
214
326
/* *
215
- * `initialWindowSize` will set the TCP read window
216
- * allowed for Http 1.1 connections and Initial Windows for H2 connections.
327
+ * Gets the client bootstrap to use for setting up and tearing down connections.
217
328
*/
218
- size_t initialWindowSize;
329
+ Io::ClientBootstrap *GetBootstrap () const noexcept { return m_bootstrap; }
330
+
219
331
/* *
220
- * See `OnConnectionSetup` for more info. This value cannot be empty .
332
+ * Sets the TCP read window allowed for Http 1.1 connections and Initial Windows for H2 connections .
221
333
*/
222
- OnConnectionSetup onConnectionSetup;
334
+ void SetInitialWindowSize (size_t initialWindowSize) noexcept
335
+ {
336
+ m_initialWindowSize = initialWindowSize;
337
+ }
338
+
339
+ /* *
340
+ * Gets the TCP read window allowed for Http 1.1 connections and Initial Windows for H2 connections.
341
+ */
342
+ size_t GetInitialWindowSize () const noexcept { return m_initialWindowSize; }
343
+
223
344
/* *
224
- * See `OnConnectionShutdown` for more info. This value cannot be empty.
345
+ * Sets the callback invoked on connection establishment, whether success or failure.
346
+ * See `OnConnectionSetup` for more info.
347
+ * This value must be set.
225
348
*/
226
- OnConnectionShutdown onConnectionShutdown;
349
+ void SetOnConnectionSetupCallback (const OnConnectionSetup &callback) noexcept
350
+ {
351
+ m_onConnectionSetup = callback;
352
+ }
227
353
228
354
/* *
229
- * hostname to connect to.
355
+ * Gets the callback invoked on connection establishment, whether success or failure.
356
+ * See `OnConnectionSetup` for more info.
230
357
*/
231
- ByteCursor hostName;
358
+ const OnConnectionSetup & GetOnConnectionSetupCallback () const noexcept { return m_onConnectionSetup; }
232
359
233
360
/* *
234
- * port on host to connect to.
361
+ * Sets the callback invoked on connection shutdown.
362
+ * See `OnConnectionShutdown` for more info.
363
+ * This value must be set.
235
364
*/
236
- uint16_t port;
365
+ void SetOnConnectionShutdownCallback (const OnConnectionShutdown &callback) noexcept
366
+ {
367
+ m_onConnectionShutdown = callback;
368
+ }
237
369
238
370
/* *
239
- * socket options to use for connection.
371
+ * Gets the callback invoked on connection shutdown.
372
+ * See `OnConnectionShutdown` for more info.
240
373
*/
241
- Io::SocketOptions *socketOptions;
374
+ const OnConnectionShutdown &GetOnConnectionShutdownCallback () const noexcept
375
+ {
376
+ return m_onConnectionShutdown;
377
+ }
242
378
243
379
/* *
244
- * Tls options to use. If null, and http (plain-text) connection will be attempted. Otherwise,
245
- * https will be used .
380
+ * Sets the name of the http server to connect to.
381
+ * This value must be set .
246
382
*/
247
- Io::TlsConnectionOptions *tlsConnOptions;
383
+ void SetHostName (const String &hostName) noexcept { m_hostName = hostName; }
384
+
385
+ /* *
386
+ * Gets the name of the http server to connect to.
387
+ */
388
+ const String &GetHostName () const noexcept { return m_hostName; }
389
+
390
+ /* *
391
+ * Sets the port of the http server to connect to.
392
+ * This value must be set.
393
+ */
394
+ void SetPort (uint16_t port) noexcept { m_port = port; }
395
+
396
+ /* *
397
+ * Gets the port of the http server to connect to
398
+ */
399
+ uint16_t GetPort () const noexcept { return m_port; }
400
+
401
+ /* *
402
+ * Sets the socket options of the connection.
403
+ * This value must be set.
404
+ */
405
+ void SetSocketOptions (const Io::SocketOptions &options) noexcept { m_socketOptions = options; }
406
+
407
+ /* *
408
+ * Gets the socket options of the connection.
409
+ */
410
+ const Io::SocketOptions &GetSocketOptions () const noexcept { return m_socketOptions; }
411
+
412
+ /* *
413
+ * Sets the TLS options for the http connection.
414
+ */
415
+ void SetTlsOptions (const Io::TlsConnectionOptions &options) noexcept { m_tlsOptions = options; }
416
+
417
+ /* *
418
+ * Gets the TLS options for the http connection.
419
+ */
420
+ const Io::TlsConnectionOptions *GetTlsOptions () const noexcept
421
+ {
422
+ return m_tlsOptions.has_value () ? &m_tlsOptions.value () : nullptr ;
423
+ }
424
+
425
+ /* *
426
+ * Sets the proxy options for the http connection.
427
+ */
428
+ void SetProxyOptions (const HttpClientConnectionProxyOptions &options) noexcept
429
+ {
430
+ m_proxyOptions = options;
431
+ }
432
+
433
+ /* *
434
+ * Gets the proxy options for the http connection.
435
+ */
436
+ const HttpClientConnectionProxyOptions *GetProxyOptions () const noexcept
437
+ {
438
+ return m_proxyOptions.has_value () ? &m_proxyOptions.value () : nullptr ;
439
+ }
440
+
441
+ private:
442
+ Io::ClientBootstrap *m_bootstrap;
443
+ size_t m_initialWindowSize;
444
+ OnConnectionSetup m_onConnectionSetup;
445
+ OnConnectionShutdown m_onConnectionShutdown;
446
+ String m_hostName;
447
+ uint16_t m_port;
448
+ Io::SocketOptions m_socketOptions;
449
+ Optional<Io::TlsConnectionOptions> m_tlsOptions;
450
+ Optional<HttpClientConnectionProxyOptions> m_proxyOptions;
248
451
};
249
452
250
453
/* *
@@ -295,7 +498,9 @@ namespace Aws
295
498
* be invoked. On success, `onConnectionSetup` will be called, either with a connection, or an
296
499
* errorCode.
297
500
*/
298
- static bool CreateConnection (const HttpClientConnectionOptions &connectionOptions) noexcept ;
501
+ static bool CreateConnection (
502
+ const HttpClientConnectionOptions &connectionOptions,
503
+ Allocator *allocator) noexcept ;
299
504
300
505
protected:
301
506
HttpClientConnection (aws_http_connection *m_connection, Allocator *allocator) noexcept ;
0 commit comments