@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'."); }
@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); } }
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); } } }
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); } }  }
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); }
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; }