From 203afee3f577b267a741630976c8f59e0ff67894 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Fri, 25 Mar 2016 13:59:32 +0100 Subject: [PATCH] Added path/query on HttpClientRequest so it's easier to get these from pushed requests --- .../io/vertx/core/http/HttpClientRequest.java | 10 +++++++ .../core/http/impl/ClientConnection.java | 2 +- .../core/http/impl/HttpClientRequestBase.java | 29 ++++++++++++++++++- .../core/http/impl/HttpClientRequestImpl.java | 28 ++---------------- .../impl/HttpClientRequestPushPromise.java | 2 +- .../io/vertx/test/core/Http2ClientTest.java | 6 ++-- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/main/java/io/vertx/core/http/HttpClientRequest.java b/src/main/java/io/vertx/core/http/HttpClientRequest.java index 27ad69e8992..edf4ec8d56a 100644 --- a/src/main/java/io/vertx/core/http/HttpClientRequest.java +++ b/src/main/java/io/vertx/core/http/HttpClientRequest.java @@ -110,6 +110,16 @@ public interface HttpClientRequest extends WriteStream, ReadStream * diff --git a/src/main/java/io/vertx/core/http/impl/ClientConnection.java b/src/main/java/io/vertx/core/http/impl/ClientConnection.java index c91d9de2f1a..fd0452fe43b 100644 --- a/src/main/java/io/vertx/core/http/impl/ClientConnection.java +++ b/src/main/java/io/vertx/core/http/impl/ClientConnection.java @@ -345,7 +345,7 @@ void handleResponseEnd(LastHttpContent trailer) { // We don't signal response end for a 100-continue response as a real response will follow // Also we keep the connection open for an HTTP CONNECT - if (currentResponse.statusCode() != 100 && requestForResponse.getMethod() != io.vertx.core.http.HttpMethod.CONNECT) { + if (currentResponse.statusCode() != 100 && requestForResponse.method() != io.vertx.core.http.HttpMethod.CONNECT) { boolean close = false; // See https://tools.ietf.org/html/rfc7230#section-6.3 diff --git a/src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java b/src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java index 652de36b797..ede3ea3bd86 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java +++ b/src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java @@ -31,14 +31,24 @@ abstract class HttpClientRequestBase implements HttpClientRequest { private static final Logger log = LoggerFactory.getLogger(HttpClientRequestImpl.class); protected final HttpClientImpl client; + protected final io.vertx.core.http.HttpMethod method; + protected final String uri; + protected final String path; + protected final String host; + protected final String query; private Handler exceptionHandler; private long currentTimeoutTimerId = -1; private long lastDataReceived; protected boolean exceptionOccurred; private Object metric; - HttpClientRequestBase(HttpClientImpl client) { + HttpClientRequestBase(HttpClientImpl client, io.vertx.core.http.HttpMethod method, String host, String uri) { this.client = client; + this.uri = uri; + this.method = method; + this.host = host; + this.path = HttpUtils.parsePath(uri); + this.query = HttpUtils.parseQuery(uri); } Object metric() { @@ -53,6 +63,23 @@ void metric(Object metric) { protected abstract void doHandleResponse(HttpClientResponseImpl resp); protected abstract void checkComplete(); + public String query() { + return query; + } + + public String path() { + return path; + } + + public String uri() { + return uri; + } + + @Override + public io.vertx.core.http.HttpMethod method() { + return method; + } + @Override public HttpClientRequest exceptionHandler(Handler handler) { synchronized (getLock()) { diff --git a/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java b/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java index 7dd4a6ed30a..6275f7b9ffa 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java +++ b/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java @@ -48,13 +48,9 @@ */ public class HttpClientRequestImpl extends HttpClientRequestBase implements HttpClientRequest { - private final String host; - private final int port; private final boolean ssl; - private final HttpClientImpl client; private final VertxInternal vertx; - private final io.vertx.core.http.HttpMethod method; - private final String uri; + private final int port; private Handler respHandler; private Handler endHandler; private boolean chunked; @@ -76,15 +72,11 @@ public class HttpClientRequestImpl extends HttpClientRequestBase implements Http HttpClientRequestImpl(HttpClientImpl client, io.vertx.core.http.HttpMethod method, String host, int port, boolean ssl, String relativeURI, VertxInternal vertx) { - super(client); - this.host = host; - this.port = port; - this.client = client; + super(client, method, host, relativeURI); this.chunked = false; - this.method = method; this.vertx = vertx; - this.uri = relativeURI; this.ssl = ssl; + this.port = port; } @Override @@ -158,16 +150,6 @@ public String getHost() { } } - @Override - public io.vertx.core.http.HttpMethod method() { - return method; - } - - @Override - public String uri() { - return uri; - } - @Override public MultiMap headers() { synchronized (getLock()) { @@ -421,10 +403,6 @@ protected void doHandleResponse(HttpClientResponseImpl resp) { } } - io.vertx.core.http.HttpMethod getMethod() { - return method; - } - // After connecting we should synchronize on the client connection instance to prevent deadlock conditions // but there is a catch - the client connection is null before connecting so we synchronized on this before that // point diff --git a/src/main/java/io/vertx/core/http/impl/HttpClientRequestPushPromise.java b/src/main/java/io/vertx/core/http/impl/HttpClientRequestPushPromise.java index 4a884603080..7fd69440702 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpClientRequestPushPromise.java +++ b/src/main/java/io/vertx/core/http/impl/HttpClientRequestPushPromise.java @@ -49,7 +49,7 @@ public HttpClientRequestPushPromise( String uri, String host, MultiMap headers) throws Http2Exception { - super(client); + super(client, method, host, uri); this.handler = handler; this.clientStream = new Http2ClientConnection.Http2ClientStream(handler, this, clientStream); this.method = method; diff --git a/src/test/java/io/vertx/test/core/Http2ClientTest.java b/src/test/java/io/vertx/test/core/Http2ClientTest.java index b9e3af3ed89..33b5d113f9b 100644 --- a/src/test/java/io/vertx/test/core/Http2ClientTest.java +++ b/src/test/java/io/vertx/test/core/Http2ClientTest.java @@ -629,7 +629,7 @@ public void testClientResetServerStream() throws Exception { public void testPushPromise() throws Exception { waitFor(2); server.requestHandler(req -> { - req.response().push(HttpMethod.GET, "/wibble", ar -> { + req.response().push(HttpMethod.GET, "/wibble?a=b", ar -> { assertTrue(ar.succeeded()); HttpServerResponse response = ar.result(); response.end("the_content"); @@ -657,7 +657,9 @@ public void testPushPromise() throws Exception { } assertOnIOContext(current); assertEquals(HttpMethod.GET, pushedReq.method()); - assertEquals("/wibble", pushedReq.uri()); + assertEquals("/wibble?a=b", pushedReq.uri()); + assertEquals("/wibble", pushedReq.path()); + assertEquals("a=b", pushedReq.query()); pushedReq.handler(resp -> { assertEquals(200, resp.statusCode()); Buffer content = Buffer.buffer();