Skip to content

Commit

Permalink
Nima: WebClient Proxy Support (#6441)
Browse files Browse the repository at this point in the history
Nima: WebClient Proxy Support #6006

Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos authored Jul 3, 2023
1 parent be9cf55 commit 47e23a3
Show file tree
Hide file tree
Showing 26 changed files with 1,520 additions and 59 deletions.
5 changes: 5 additions & 0 deletions common/http/src/main/java/io/helidon/common/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public static final class Method {
*/
public static final Method PATCH = new Method("PATCH", true);

/**
* The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel.
*/
public static final Method CONNECT = new Method("CONNECT", true);

static {
// THIS MUST BE AFTER THE LAST CONSTANT
MethodHelper.methodsDone();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,6 +56,16 @@ public static SocketWriter create(ExecutorService executor,
}
}

/**
* Create a new socket writer.
*
* @param socket socket to write to
* @return a new socket writer
*/
public static SocketWriter create(HelidonSocket socket) {
return new SocketWriterDirect(socket);
}

@Override
public void writeNow(BufferData... buffers) {
BufferData composite = BufferData.create(buffers);
Expand Down
22 changes: 22 additions & 0 deletions nima/common/tls/src/main/java/io/helidon/nima/common/tls/Tls.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -196,6 +198,26 @@ public SSLSocket createSocket(String alpnProtocol) {
}
}

/**
* Create a SSLSocket for the chosen protocol and the given socket.
*
* @param alpnProtocol protocol to use
* @param socket existing socket
* @param address where SSL socket will connect
* @return a new socket ready for TLS communication
*/
public SSLSocket createSocket(String alpnProtocol, Socket socket, InetSocketAddress address) {
try {
SSLSocket sslSocket = (SSLSocket) sslSocketFactory
.createSocket(socket, address.getHostName(), address.getPort(), true);
sslParameters.setApplicationProtocols(new String[] {alpnProtocol});
sslSocket.setSSLParameters(sslParameters);
return sslSocket;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/**
* SSL context based on the configured values.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.helidon.nima.http2.Http2Headers;
import io.helidon.nima.webclient.ClientConnection;
import io.helidon.nima.webclient.ClientRequest;
import io.helidon.nima.webclient.Proxy;
import io.helidon.nima.webclient.UriHelper;

class ClientRequestImpl implements Http2ClientRequest {
Expand Down Expand Up @@ -371,4 +372,9 @@ public void accept(HeaderValue httpHeader) {
}
}
}

@Override
public Http2ClientRequest proxy(Proxy proxy) {
throw new UnsupportedOperationException("Proxy is not supported in HTTP2");
}
}
7 changes: 1 addition & 6 deletions nima/tests/integration/webclient/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,14 +13,11 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.helidon.nima.tests.integration</groupId>
<artifactId>helidon-nima-tests-integration-project</artifactId>
Expand All @@ -31,7 +27,6 @@
<groupId>io.helidon.nima.tests.integration.webclient</groupId>
<artifactId>helidon-nima-tests-integration-webclient-project</artifactId>
<name>Helidon Níma Tests Integration WebClient Project</name>

<packaging>pom</packaging>

<modules>
Expand Down
11 changes: 1 addition & 10 deletions nima/tests/integration/webclient/webclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
</parent>

<artifactId>helidon-nima-tests-integration-webclient</artifactId>
<name>Helidon Níma Tests Integration WebClient</name>

<properties>
<spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
</properties>
<name>Helidon Níma Tests Integration Webclient</name>

<dependencies>
<dependency>
Expand All @@ -46,11 +42,6 @@
<artifactId>helidon-nima-testing-junit5-webserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.common.testing</groupId>
<artifactId>helidon-common-testing-http-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Loading

0 comments on commit 47e23a3

Please sign in to comment.