File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 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
133133
134134 // Here there be dragons.
135135 Pattern urlPattern =
136- Pattern .compile ("^(https?) ://(([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\ d+))?/?$" );
136+ Pattern .compile ("^(https?://)? (([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\ d+))?/?$" );
137137 Matcher matcher = urlPattern .matcher (proxyAddress );
138138 if (!matcher .matches ()) {
139139 throw new IOException ("Proxy address " + proxyAddress + " is not a valid URL" );
@@ -153,15 +153,19 @@ public static Proxy createProxy(@Nullable String proxyAddress) throws IOExceptio
153153 }
154154
155155 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+ }
165169 }
166170
167171 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 {
204204
205205 @ Test
206206 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" );
210209 }
211210
212211 @ Test
213212 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" );
219215 }
220216
221217 @ Test
You can’t perform that action at this time.
0 commit comments