@@ -53,8 +53,9 @@ void aws_http_proxy_user_data_destroy(struct aws_http_proxy_user_data *user_data
53
53
}
54
54
55
55
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
+ }
58
59
59
60
if (user_data -> tls_options ) {
60
61
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(
68
69
struct aws_allocator * allocator ,
69
70
const struct aws_http_client_connection_options * options ) {
70
71
72
+ AWS_FATAL_ASSERT (options -> proxy_options != NULL );
73
+
71
74
struct aws_http_proxy_user_data * user_data = aws_mem_calloc (allocator , 1 , sizeof (struct aws_http_proxy_user_data ));
72
75
if (user_data == NULL ) {
73
76
return NULL ;
@@ -83,19 +86,10 @@ struct aws_http_proxy_user_data *aws_http_proxy_user_data_new(
83
86
}
84
87
85
88
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
- }
93
89
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 ;
99
93
}
100
94
101
95
if (options -> tls_options ) {
@@ -146,12 +140,12 @@ static int s_add_basic_proxy_authentication_header(
146
140
if (aws_byte_buf_init (
147
141
& base64_input_value ,
148
142
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 )) {
150
144
goto done ;
151
145
}
152
146
153
147
/* 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 );
155
149
if (aws_byte_buf_append (& base64_input_value , & username_cursor )) {
156
150
goto done ;
157
151
}
@@ -161,7 +155,7 @@ static int s_add_basic_proxy_authentication_header(
161
155
goto done ;
162
156
}
163
157
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 );
165
159
if (aws_byte_buf_append (& base64_input_value , & password_cursor )) {
166
160
goto done ;
167
161
}
@@ -345,7 +339,8 @@ static struct aws_http_message *s_build_proxy_connect_request(struct aws_http_pr
345
339
goto on_error ;
346
340
}
347
341
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 )) {
349
344
goto on_error ;
350
345
}
351
346
@@ -672,7 +667,8 @@ static int s_proxy_http_request_transform(struct aws_http_message *request, void
672
667
673
668
int result = AWS_OP_ERR ;
674
669
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 )) {
676
672
goto done ;
677
673
}
678
674
@@ -791,3 +787,74 @@ int aws_http_client_connect_via_proxy(const struct aws_http_client_connection_op
791
787
return s_aws_http_client_connect_via_proxy_http (options );
792
788
}
793
789
}
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