Skip to content

Commit

Permalink
feat: proxy configs support proxy URLs without a scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored May 3, 2024
1 parent c7ee655 commit c6437af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix #5866: Addressed cycle in crd generation with Java 19+ and ZonedDateTime

#### Improvements
* Fix #5605: proxy configs support proxy URLs without a scheme
* Fix #5878: (java-generator) Add implements Editable for extraAnnotations
* Fix #5878: (java-generator) Update documentation to include dependencies
* Fix #5867: (crd-generator) Imply schemaFrom via JsonFormat shape (SchemaFrom takes precedence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ static URI getProxyUri(URL master, Config config) throws URISyntaxException {
proxy = config.getHttpProxy();
}
if (proxy != null) {
URI proxyUrl = new URI(proxy);
final String completedProxy;
if (proxy.contains("://")) {
completedProxy = proxy;
} else {
// No protocol specified, default to cluster requirements
completedProxy = master.getProtocol() + "://" + proxy;
}
final URI proxyUrl = new URI(completedProxy);
if (proxyUrl.getPort() < 0) {
throw new IllegalArgumentException("Failure in creating proxy URL. Proxy port is required!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
class HttpClientUtilsTest {

@Test
void toProxyTypeTestUnknown() throws MalformedURLException {
void toProxyTypeTestUnknown() {
assertThrows(MalformedURLException.class, () -> HttpClientUtils.toProxyType("unknown"));
}

@Test
void toProxyTypeTestNull() throws MalformedURLException {
void toProxyTypeTestNull() {
assertThrows(MalformedURLException.class, () -> HttpClientUtils.toProxyType(null));
}

Expand Down Expand Up @@ -160,7 +160,7 @@ void setUp() {
@ParameterizedTest(name = "{index}: Master hostname ''{0}'' matched by No Proxy ''{1}'' ")
@MethodSource("masterHostnameDoesMatchNoProxyInput")
void masterHostnameDoesMatchNoProxy(String masterHostname, String[] noProxy)
throws MalformedURLException, URISyntaxException {
throws MalformedURLException {
assertTrue(HttpClientUtils.isHostMatchedByNoProxy(masterHostname, noProxy));
}

Expand Down Expand Up @@ -236,6 +236,19 @@ void withNoHttpProxyProvidedReturnsNull() throws MalformedURLException, URISynta
// Then
assertThat(url).isNull();
}

@Test
void whenIncompleteHttpProxyUrlProvided_shouldInferProtocol() throws MalformedURLException, URISyntaxException {
// Given
Config config = configBuilder.withHttpProxy("example.com:8080").build();
// When
URI url = HttpClientUtils.getProxyUri(new URL("http://localhost"), config);
// Then
assertThat(url)
.hasScheme("http")
.hasHost("example.com")
.hasPort(8080);
}
}

@Nested
Expand Down

0 comments on commit c6437af

Please sign in to comment.