Skip to content

Commit

Permalink
Add ProxyConfig new from ProxyOptions & TLS info (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Feb 3, 2023
1 parent 9d67050 commit 9989461
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
15 changes: 15 additions & 0 deletions include/aws/http/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,21 @@ struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options(
struct aws_allocator *allocator,
const struct aws_http_proxy_options *options);

/**
* Create a persistent proxy configuration from non-persistent proxy options.
*
* @param allocator memory allocator to use
* @param options http proxy options to source proxy configuration from
* @param is_tls_connection tls connection info of the main connection to determine connection_type
* when the connection_type is legacy.
* @return
*/
AWS_HTTP_API
struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options_with_tls_info(
struct aws_allocator *allocator,
const struct aws_http_proxy_options *proxy_options,
bool is_tls_connection);

/**
* Clones an existing proxy configuration. A refactor could remove this (do a "move" between the old and new user
* data in the one spot it's used) but that should wait until we have better test cases for the logic where this
Expand Down
21 changes: 16 additions & 5 deletions source/proxy_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,12 @@ static int s_aws_http_client_connect_via_tunneling_proxy(

static enum aws_http_proxy_connection_type s_determine_proxy_connection_type(
enum aws_http_proxy_connection_type proxy_connection_type,
const struct aws_tls_connection_options *tls_options) {
bool is_tls_connection) {
if (proxy_connection_type != AWS_HPCT_HTTP_LEGACY) {
return proxy_connection_type;
}

if (tls_options != NULL) {
if (is_tls_connection) {
return AWS_HPCT_HTTP_TUNNEL;
} else {
return AWS_HPCT_HTTP_FORWARD;
Expand Down Expand Up @@ -1184,7 +1184,7 @@ static int s_connect_proxy(const struct aws_http_client_connection_options *opti
}

enum aws_http_proxy_connection_type proxy_connection_type =
s_determine_proxy_connection_type(options->proxy_options->connection_type, options->tls_options);
s_determine_proxy_connection_type(options->proxy_options->connection_type, options->tls_options != NULL);

switch (proxy_connection_type) {
case AWS_HPCT_HTTP_FORWARD:
Expand Down Expand Up @@ -1398,7 +1398,7 @@ struct aws_http_proxy_config *aws_http_proxy_config_new_from_connection_options(
return s_aws_http_proxy_config_new(
allocator,
options->proxy_options,
s_determine_proxy_connection_type(options->proxy_options->connection_type, options->tls_options));
s_determine_proxy_connection_type(options->proxy_options->connection_type, options->tls_options != NULL));
}

struct aws_http_proxy_config *aws_http_proxy_config_new_from_manager_options(
Expand All @@ -1410,7 +1410,8 @@ struct aws_http_proxy_config *aws_http_proxy_config_new_from_manager_options(
return s_aws_http_proxy_config_new(
allocator,
options->proxy_options,
s_determine_proxy_connection_type(options->proxy_options->connection_type, options->tls_connection_options));
s_determine_proxy_connection_type(
options->proxy_options->connection_type, options->tls_connection_options != NULL));
}

struct aws_http_proxy_config *aws_http_proxy_config_new_tunneling_from_proxy_options(
Expand All @@ -1431,6 +1432,16 @@ struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options(
return s_aws_http_proxy_config_new(allocator, proxy_options, proxy_options->connection_type);
}

struct aws_http_proxy_config *aws_http_proxy_config_new_from_proxy_options_with_tls_info(
struct aws_allocator *allocator,
const struct aws_http_proxy_options *proxy_options,
bool is_tls_connection) {
AWS_FATAL_ASSERT(proxy_options != NULL);

return s_aws_http_proxy_config_new(
allocator, proxy_options, s_determine_proxy_connection_type(proxy_options->connection_type, is_tls_connection));
}

struct aws_http_proxy_config *aws_http_proxy_config_new_clone(
struct aws_allocator *allocator,
const struct aws_http_proxy_config *proxy_config) {
Expand Down

0 comments on commit 9989461

Please sign in to comment.