@@ -53,8 +53,9 @@ void aws_http_proxy_user_data_destroy(struct aws_http_proxy_user_data *user_data
5353 }
5454
5555 aws_string_destroy (user_data -> original_host );
56- aws_string_destroy (user_data -> username );
57- aws_string_destroy (user_data -> password );
56+ if (user_data -> proxy_config ) {
57+ aws_http_proxy_config_destroy (user_data -> proxy_config );
58+ }
5859
5960 if (user_data -> tls_options ) {
6061 aws_tls_connection_options_clean_up (user_data -> tls_options );
@@ -68,6 +69,8 @@ struct aws_http_proxy_user_data *aws_http_proxy_user_data_new(
6869 struct aws_allocator * allocator ,
6970 const struct aws_http_client_connection_options * options ) {
7071
72+ AWS_FATAL_ASSERT (options -> proxy_options != NULL );
73+
7174 struct aws_http_proxy_user_data * user_data = aws_mem_calloc (allocator , 1 , sizeof (struct aws_http_proxy_user_data ));
7275 if (user_data == NULL ) {
7376 return NULL ;
@@ -83,19 +86,10 @@ struct aws_http_proxy_user_data *aws_http_proxy_user_data_new(
8386 }
8487
8588 user_data -> original_port = options -> port ;
86- user_data -> auth_type = options -> proxy_options -> auth_type ;
87- if (user_data -> auth_type == AWS_HPAT_BASIC ) {
88- const struct aws_byte_cursor * user_name = & options -> proxy_options -> auth_username ;
89- user_data -> username = aws_string_new_from_array (allocator , user_name -> ptr , user_name -> len );
90- if (user_data -> username == NULL ) {
91- goto on_error ;
92- }
9389
94- const struct aws_byte_cursor * password = & options -> proxy_options -> auth_password ;
95- user_data -> password = aws_string_new_from_array (allocator , password -> ptr , password -> len );
96- if (user_data -> password == NULL ) {
97- goto on_error ;
98- }
90+ user_data -> proxy_config = aws_http_proxy_config_new (allocator , options -> proxy_options );
91+ if (user_data -> proxy_config == NULL ) {
92+ goto on_error ;
9993 }
10094
10195 if (options -> tls_options ) {
@@ -146,12 +140,12 @@ static int s_add_basic_proxy_authentication_header(
146140 if (aws_byte_buf_init (
147141 & base64_input_value ,
148142 proxy_user_data -> allocator ,
149- proxy_user_data -> username -> len + proxy_user_data -> password -> len + 1 )) {
143+ proxy_user_data -> proxy_config -> auth_username . len + proxy_user_data -> proxy_config -> auth_password . len + 1 )) {
150144 goto done ;
151145 }
152146
153147 /* First build a buffer with "username:password" in it */
154- struct aws_byte_cursor username_cursor = aws_byte_cursor_from_string ( proxy_user_data -> username );
148+ struct aws_byte_cursor username_cursor = aws_byte_cursor_from_buf ( & proxy_user_data -> proxy_config -> auth_username );
155149 if (aws_byte_buf_append (& base64_input_value , & username_cursor )) {
156150 goto done ;
157151 }
@@ -161,7 +155,7 @@ static int s_add_basic_proxy_authentication_header(
161155 goto done ;
162156 }
163157
164- struct aws_byte_cursor password_cursor = aws_byte_cursor_from_string ( proxy_user_data -> password );
158+ struct aws_byte_cursor password_cursor = aws_byte_cursor_from_buf ( & proxy_user_data -> proxy_config -> auth_password );
165159 if (aws_byte_buf_append (& base64_input_value , & password_cursor )) {
166160 goto done ;
167161 }
@@ -345,7 +339,8 @@ static struct aws_http_message *s_build_proxy_connect_request(struct aws_http_pr
345339 goto on_error ;
346340 }
347341
348- if (user_data -> auth_type == AWS_HPAT_BASIC && s_add_basic_proxy_authentication_header (request , user_data )) {
342+ if (user_data -> proxy_config -> auth_type == AWS_HPAT_BASIC &&
343+ s_add_basic_proxy_authentication_header (request , user_data )) {
349344 goto on_error ;
350345 }
351346
@@ -672,7 +667,8 @@ static int s_proxy_http_request_transform(struct aws_http_message *request, void
672667
673668 int result = AWS_OP_ERR ;
674669
675- if (proxy_ud -> auth_type == AWS_HPAT_BASIC && s_add_basic_proxy_authentication_header (request , proxy_ud )) {
670+ if (proxy_ud -> proxy_config -> auth_type == AWS_HPAT_BASIC &&
671+ s_add_basic_proxy_authentication_header (request , proxy_ud )) {
676672 goto done ;
677673 }
678674
@@ -791,3 +787,74 @@ int aws_http_client_connect_via_proxy(const struct aws_http_client_connection_op
791787 return s_aws_http_client_connect_via_proxy_http (options );
792788 }
793789}
790+
791+ struct aws_http_proxy_config * aws_http_proxy_config_new (
792+ struct aws_allocator * allocator ,
793+ const struct aws_http_proxy_options * options ) {
794+ AWS_FATAL_ASSERT (options != NULL );
795+ struct aws_http_proxy_config * config = aws_mem_calloc (allocator , 1 , sizeof (struct aws_http_proxy_config ));
796+ if (config == NULL ) {
797+ return NULL ;
798+ }
799+
800+ if (aws_byte_buf_init_copy_from_cursor (& config -> host , allocator , options -> host )) {
801+ goto on_error ;
802+ }
803+
804+ if (aws_byte_buf_init_copy_from_cursor (& config -> auth_username , allocator , options -> auth_username )) {
805+ goto on_error ;
806+ }
807+
808+ if (aws_byte_buf_init_copy_from_cursor (& config -> auth_password , allocator , options -> auth_password )) {
809+ goto on_error ;
810+ }
811+
812+ if (options -> tls_options ) {
813+ config -> tls_options = aws_mem_calloc (allocator , 1 , sizeof (struct aws_tls_connection_options ));
814+ if (aws_tls_connection_options_copy (config -> tls_options , options -> tls_options )) {
815+ goto on_error ;
816+ }
817+ }
818+
819+ config -> allocator = allocator ;
820+ config -> auth_type = options -> auth_type ;
821+ config -> port = options -> port ;
822+
823+ return config ;
824+
825+ on_error :
826+
827+ aws_http_proxy_config_destroy (config );
828+
829+ return NULL ;
830+ }
831+
832+ void aws_http_proxy_config_destroy (struct aws_http_proxy_config * config ) {
833+ if (config == NULL ) {
834+ return ;
835+ }
836+
837+ aws_byte_buf_clean_up (& config -> host );
838+ aws_byte_buf_clean_up (& config -> auth_username );
839+ aws_byte_buf_clean_up (& config -> auth_password );
840+
841+ if (config -> tls_options ) {
842+ aws_tls_connection_options_clean_up (config -> tls_options );
843+ aws_mem_release (config -> allocator , config -> tls_options );
844+ }
845+
846+ aws_mem_release (config -> allocator , config );
847+ }
848+
849+ void aws_http_proxy_options_init_from_config (
850+ struct aws_http_proxy_options * options ,
851+ const struct aws_http_proxy_config * config ) {
852+ AWS_FATAL_ASSERT (options && config );
853+
854+ options -> host = aws_byte_cursor_from_buf (& config -> host );
855+ options -> auth_username = aws_byte_cursor_from_buf (& config -> auth_username );
856+ options -> auth_password = aws_byte_cursor_from_buf (& config -> auth_password );
857+ options -> auth_type = config -> auth_type ;
858+ options -> port = config -> port ;
859+ options -> tls_options = config -> tls_options ;
860+ }
0 commit comments