Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Jun 27, 2023
1 parent 0ab0c06 commit a2168e5
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 74 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
2 changes: 1 addition & 1 deletion nima/tests/integration/webclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>io.helidon.nima.tests.integration.webclient</groupId>
<artifactId>helidon-nima-tests-integration-webclient-project</artifactId>
<name>Helidon Níma Tests Integration WebServer Project</name>
<name>Helidon Níma Tests Integration WebClient Project</name>
<packaging>pom</packaging>

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

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

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class HttpProxy {
private final String password;
// Starts with -1 because there is one first test connection to verify the HttpProxy is available
private final AtomicInteger counter = new AtomicInteger(-1);
private int connectedPort;

HttpProxy(int port, String user, String password) {
this.port = port;
Expand All @@ -54,8 +55,9 @@ class HttpProxy {

boolean start() {
executor.submit(() -> {
LOGGER.log(Level.INFO, "Listening connections in port: " + port);
try (ServerSocket server = new ServerSocket(port)) {
this.connectedPort = server.getLocalPort();
LOGGER.log(Level.INFO, "Listening connections in port: " + connectedPort);
while (!stop) {
Socket origin = server.accept();
LOGGER.log(Level.DEBUG, "Open: " + origin);
Expand All @@ -78,7 +80,7 @@ boolean start() {
boolean responding = false;
while (!responding) {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(port), 10000);
socket.connect(new InetSocketAddress(connectedPort), 10000);
responding = true;
} catch (IOException e) {}
}
Expand All @@ -94,14 +96,18 @@ boolean stop() {
try {
// Make the server to check stop boolean
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(port), 10000);
socket.connect(new InetSocketAddress(connectedPort), 10000);
} catch (IOException e) {}
return executor.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return false;
}
}

int connectedPort() {
return connectedPort;
}

private class MiddleCommunicator {

private static final System.Logger LOGGER = System.getLogger(MiddleCommunicator.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class HttpProxyTest {

private static final String PROXY_HOST = "localhost";
private static final int PROXY_PORT = 18081;
private int proxyPort;
private HttpProxy httpProxy;

private final Http1Client client;
Expand All @@ -49,8 +49,9 @@ static void routing(HttpRouting.Builder router) {

@BeforeEach
public void before() {
httpProxy = new HttpProxy(PROXY_PORT);
httpProxy = new HttpProxy(0);
httpProxy.start();
proxyPort = httpProxy.connectedPort();
}

@AfterEach
Expand All @@ -74,7 +75,7 @@ void testNoProxy() {

@Test
void testNoHosts() {
Proxy proxy = Proxy.builder().host(PROXY_HOST).port(PROXY_PORT).addNoProxy(PROXY_HOST).build();
Proxy proxy = Proxy.builder().host(PROXY_HOST).port(proxyPort).addNoProxy(PROXY_HOST).build();
try (Http1ClientResponse response = client.get("/get").proxy(proxy).request()) {
assertThat(response.status(), is(Http.Status.OK_200));
String entity = response.entity().as(String.class);
Expand All @@ -85,13 +86,13 @@ void testNoHosts() {

@Test
void testNoProxyType() {
Proxy proxy = Proxy.builder().host(PROXY_HOST).port(PROXY_PORT).build();
Proxy proxy = Proxy.builder().host(PROXY_HOST).port(proxyPort).build();
successVerify(proxy);
}

@Test
void testSimpleProxy() {
Proxy proxy = Proxy.builder().type(ProxyType.HTTP).host(PROXY_HOST).port(PROXY_PORT).build();
Proxy proxy = Proxy.builder().type(ProxyType.HTTP).host(PROXY_HOST).port(proxyPort).build();
successVerify(proxy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.io.IOException;

import io.helidon.common.configurable.Resource;
import io.helidon.common.http.Http;
import io.helidon.common.pki.Keys;
Expand All @@ -44,8 +46,8 @@
class HttpsProxyTest {

private static final String PROXY_HOST = "localhost";
private static final int PROXY_PORT = 18081;
private static final HttpProxy httpProxy = new HttpProxy(PROXY_PORT);
private static int PROXY_PORT;
private static HttpProxy httpProxy;

private final Http1Client client;

Expand Down Expand Up @@ -73,8 +75,10 @@ static void routing(HttpRouting.Builder router) {
}

@BeforeAll
public static void beforeAll() {
public static void beforeAll() throws IOException {
httpProxy = new HttpProxy(0);
httpProxy.start();
PROXY_PORT = httpProxy.connectedPort();
}

@AfterAll
Expand Down
4 changes: 2 additions & 2 deletions nima/webclient/webclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<artifactId>helidon-nima-common-tls</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.nima.http.media</groupId>
Expand Down
Loading

0 comments on commit a2168e5

Please sign in to comment.