File tree 2 files changed +18
-18
lines changed
main/java/com/google/devtools/build/lib/bazel/repository/downloader
test/java/com/google/devtools/build/lib/bazel/repository/downloader
2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ public static Proxy createProxy(@Nullable String proxyAddress) throws IOExceptio
133
133
134
134
// Here there be dragons.
135
135
Pattern urlPattern =
136
- Pattern .compile ("^(https?) ://(([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\ d+))?/?$" );
136
+ Pattern .compile ("^(https?://)? (([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\ d+))?/?$" );
137
137
Matcher matcher = urlPattern .matcher (proxyAddress );
138
138
if (!matcher .matches ()) {
139
139
throw new IOException ("Proxy address " + proxyAddress + " is not a valid URL" );
@@ -153,15 +153,19 @@ public static Proxy createProxy(@Nullable String proxyAddress) throws IOExceptio
153
153
}
154
154
155
155
boolean https ;
156
- switch (protocol ) {
157
- case "https" :
158
- https = true ;
159
- break ;
160
- case "http" :
161
- https = false ;
162
- break ;
163
- default :
164
- throw new IOException ("Invalid proxy protocol for " + cleanProxyAddress );
156
+ if (protocol == null ) {
157
+ https = false ;
158
+ } else {
159
+ switch (protocol ) {
160
+ case "https://" :
161
+ https = true ;
162
+ break ;
163
+ case "http://" :
164
+ https = false ;
165
+ break ;
166
+ default :
167
+ throw new IOException ("Invalid proxy protocol for " + cleanProxyAddress );
168
+ }
165
169
}
166
170
167
171
int port = https ? 443 : 80 ; // Default port numbers
Original file line number Diff line number Diff line change @@ -204,18 +204,14 @@ public void testProxyExplicitPort() throws Exception {
204
204
205
205
@ Test
206
206
public void testProxyNoProtocol () throws Exception {
207
- IOException e =
208
- assertThrows (IOException .class , () -> ProxyHelper .createProxy ("my.example.com" ));
209
- assertThat (e ).hasMessageThat ().contains ("Proxy address my.example.com is not a valid URL" );
207
+ Proxy proxy = ProxyHelper .createProxy ("my.example.com" );
208
+ assertThat (proxy .toString ()).endsWith (":80" );
210
209
}
211
210
212
211
@ Test
213
212
public void testProxyNoProtocolWithPort () throws Exception {
214
- IOException e =
215
- assertThrows (IOException .class , () -> ProxyHelper .createProxy ("my.example.com:12345" ));
216
- assertThat (e )
217
- .hasMessageThat ()
218
- .contains ("Proxy address my.example.com:12345 is not a valid URL" );
213
+ Proxy proxy = ProxyHelper .createProxy ("my.example.com:12345" );
214
+ assertThat (proxy .toString ()).endsWith (":12345" );
219
215
}
220
216
221
217
@ Test
You can’t perform that action at this time.
0 commit comments