Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nima Proxy TODOs #7168

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum HeaderEnum implements Http.HeaderName {
LINK("Link"),
LOCATION("Location"),
PRAGMA("Pragma"),
PROXY_CONNECTION("Proxy-Connection"),
PUBLIC_KEY_PINS("Public-Key-Pins"),
RETRY_AFTER("Retry-After"),
SERVER("Server"),
Expand Down
7 changes: 7 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 @@ -1332,6 +1332,13 @@ public static final class Header {
* Implementation-specific fields that may have various effects anywhere along the request-response chain.
*/
public static final HeaderName PRAGMA = HeaderEnum.PRAGMA;
/**
* The {@code Proxy-Connection} header name.
* Implemented as a misunderstanding of the HTTP specifications. Common because of mistakes in
* implementations of early HTTP versions. Has exactly the same functionality as standard
* Connection field. Must not be used with HTTP/2.
*/
public static final HeaderName PROXY_CONNECTION = HeaderEnum.PROXY_CONNECTION;
/**
* The {@code Public-Key-Pins} header name.
* HTTP Public Key Pinning, announces hash of website's authentic TLS certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
Expand Down Expand Up @@ -68,6 +69,7 @@ class ClientRequestImpl implements Http2ClientRequest {
private int requestPrefetch = 0;
private int maxRedirects;
private ClientConnection explicitConnection;
private Proxy proxy;
private Duration flowControlTimeout = Duration.ofMillis(100);
private Duration timeout = Duration.ofSeconds(10);
private UriFragment fragment = UriFragment.empty();
Expand Down Expand Up @@ -337,7 +339,8 @@ private Http2ClientStream newStream(UriHelper uri) {
priorKnowledge,
tls,
client.dnsResolver(),
client.dnsAddressLookup());
client.dnsAddressLookup(),
proxy);

// this statement locks all threads - must not do anything complicated (just create a new instance)
return CHANNEL_CACHE.computeIfAbsent(connectionKey,
Expand Down Expand Up @@ -375,6 +378,8 @@ public void accept(HeaderValue httpHeader) {

@Override
public Http2ClientRequest proxy(Proxy proxy) {
throw new UnsupportedOperationException("Proxy is not supported in HTTP2");
this.proxy = Objects.requireNonNull(proxy);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.helidon.common.http.Http;
import io.helidon.nima.http.media.ReadableEntity;
import io.helidon.nima.http2.Http2Headers;
import io.helidon.nima.webclient.ClientConnection;
import io.helidon.nima.webclient.UriHelper;

class ClientResponseImpl implements Http2ClientResponse {
Expand Down Expand Up @@ -58,6 +59,11 @@ public URI lastEndpointUri() {
return lastEndpointUri.toUri();
}

@Override
public ClientConnection connection() {
throw new UnsupportedOperationException("Not supported");
}

@Override
public void close() {
if (stream != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import io.helidon.common.http.Http;
import io.helidon.nima.common.tls.Tls;
import io.helidon.nima.webclient.DnsAddressLookup;
import io.helidon.nima.webclient.Proxy;
import io.helidon.nima.webclient.spi.DnsResolver;

record ConnectionKey(Http.Method method, String scheme, String host, int port, boolean priorKnowledge, Tls tls,
DnsResolver dnsResolver, DnsAddressLookup dnsAddressLookup) {
DnsResolver dnsResolver, DnsAddressLookup dnsAddressLookup, Proxy proxy) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import io.helidon.nima.http2.Http2Settings;
import io.helidon.nima.http2.Http2WindowUpdate;
import io.helidon.nima.http2.WindowSize;
import io.helidon.nima.webclient.Proxy;
import io.helidon.nima.webclient.spi.DnsResolver;

import static java.lang.System.Logger.Level.DEBUG;
Expand Down Expand Up @@ -312,7 +313,7 @@ private void handle() {

private void doConnect() throws IOException {
boolean useTls = "https".equals(connectionKey.scheme()) && connectionKey.tls() != null;

Proxy proxy = connectionKey.proxy();
SSLSocket sslSocket = useTls ? connectionKey.tls().createSocket("h2") : null;
socket = sslSocket == null ? new Socket() : sslSocket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.helidon.nima.testing.junit5.webserver;

import java.net.Socket;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
Expand Down Expand Up @@ -88,6 +89,11 @@ public void readTimeout(Duration readTimeout) {
//NOOP
}

@Override
public Socket socket() {
throw new UnsupportedOperationException("Socket does not exist in direct connection");
}

private DataWriter writer(ArrayBlockingQueue<byte[]> queue) {
return new DataWriter() {
@Override
Expand Down Expand Up @@ -153,4 +159,5 @@ private void startServer() {
}
});
}

}
4 changes: 4 additions & 0 deletions nima/tests/integration/webclient/webclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<groupId>io.helidon.nima.webclient</groupId>
<artifactId>helidon-nima-webclient</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.nima.http2</groupId>
<artifactId>helidon-nima-http2-webclient</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nima/webclient/webclient/etc/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<!--
This is an implementation of an HTTP client, where a user may want to connect to plain socket.
-->
<Class name="io.helidon.nima.webclient.http1.Http1ClientConnection"/>
<Class name="io.helidon.nima.webclient.ConnectionStrategy"/>
<Bug pattern="UNENCRYPTED_SOCKET"/>
</Match>
<Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.helidon.nima.webclient;

import java.net.Socket;
import java.time.Duration;

import io.helidon.common.buffers.DataReader;
Expand Down Expand Up @@ -63,4 +64,11 @@ public interface ClientConnection {
* @param readTimeout connection read timeout
*/
void readTimeout(Duration readTimeout);

/**
* Socket of the connection.
*
* @return socket of the connection
*/
Socket socket();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ default <T extends Source<?>> void source(GenericType<T> sourceType, T source) {
*/
@Override
void close();

/**
* Return the current response connection.
* This is necessary for proxies because they need to re-use the same connection.
*
* @return the connection of the request
*/
ClientConnection connection();
}
Loading