HttpTransportFactory { @VisibleForTesting static URI parseProxyAddress(@Nullable String proxyAddress) { if (Strings.isNullOrEmpty(proxyAddress)) { return null; } String uriString = (proxyAddress.contains(" try { URI uri = new URI(uriString); String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); checkArgument( Strings.isNullOrEmpty(scheme) || scheme.matches("https?"), "HTTP proxy address '%s' has invalid scheme '%s'.", proxyAddress, scheme); checkArgument(!Strings.isNullOrEmpty(host), "Proxy address '%s' has no host.", proxyAddress); checkArgument(port != -1, "Proxy address '%s' has no port.", proxyAddress); checkArgument( uri.equals(new URI(scheme, null, host, port, null, null, null)), "Invalid proxy address '%s'.", proxyAddress); return uri; } catch (URISyntaxException e) { throw new IllegalArgumentException( String.format("Invalid proxy address '%s'.", proxyAddress), e); } }  static HttpTransport createHttpTransport(HttpTransportType type); static HttpTransport createHttpTransport(
      HttpTransportType type,
      @Nullable String proxyAddress,
      @Nullable RedactedString proxyUsername,
      @Nullable RedactedString proxyPassword); static ApacheHttpTransport createApacheHttpTransport(
      @Nullable URI proxyUri, @Nullable Credentials proxyCredentials); static NetHttpTransport createNetHttpTransport(
      @Nullable URI proxyUri, @Nullable PasswordAuthentication proxyAuth); static final HttpTransportType DEFAULT_TRANSPORT_TYPE; }
@Test public void testParseProxyAddress() throws Exception { String address = "foo-host:1234"; URI expectedUri = getURI(null, "foo-host", 1234); URI uri = HttpTransportFactory.parseProxyAddress(address); assertThat(uri).isEqualTo(expectedUri); }
@Test public void testParseProxyAddressHttp() throws Exception { String address = "http: URI expectedUri = getURI("http", "foo-host", 1234); URI uri = HttpTransportFactory.parseProxyAddress(address); assertThat(uri).isEqualTo(expectedUri); }
@Test public void testParseProxyAddressHttps() throws Exception { String address = "https: URI expectedUri = getURI("https", "foo-host", 1234); URI uri = HttpTransportFactory.parseProxyAddress(address); assertThat(uri).isEqualTo(expectedUri); }
@Test public void testParseProxyAddressInvalidScheme() throws Exception { String address = "socks5: IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> HttpTransportFactory.parseProxyAddress(address)); assertThat(thrown) .hasMessageThat() .contains("HTTP proxy address 'socks5: }
@Test public void testParseProxyAddressNoHost() throws Exception { String address = ":1234"; IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> HttpTransportFactory.parseProxyAddress(address)); assertThat(thrown).hasMessageThat().contains("Proxy address ':1234' has no host."); }
@Test public void testParseProxyAddressNoPort() throws Exception { String address = "foo-host"; IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> HttpTransportFactory.parseProxyAddress(address)); assertThat(thrown).hasMessageThat().contains("Proxy address 'foo-host' has no port."); }
@Test public void testParseProxyAddressInvalidSyntax() throws Exception { String address = "foo-host-with-illegal-char^:1234"; IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> HttpTransportFactory.parseProxyAddress(address)); assertThat(thrown) .hasMessageThat() .contains("Invalid proxy address 'foo-host-with-illegal-char^:1234'."); }
@Test public void testParseProxyAddressWithPath() throws Exception { String address = "foo-host:1234/some/path"; IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> HttpTransportFactory.parseProxyAddress(address)); assertThat(thrown) .hasMessageThat() .contains("Invalid proxy address 'foo-host:1234/some/path'."); }