Skip to content

Commit

Permalink
Added path/query on HttpClientRequest so it's easier to get these fro…
Browse files Browse the repository at this point in the history
…m pushed requests
  • Loading branch information
vietj committed Mar 25, 2016
1 parent 4da6ba4 commit 203afee
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/vertx/core/http/HttpClientRequest.java
Expand Up @@ -110,6 +110,16 @@ public interface HttpClientRequest extends WriteStream<Buffer>, ReadStream<HttpC
*/ */
String uri(); String uri();


/**
* @return The path part of the uri. For example /somepath/somemorepath/someresource.foo
*/
String path();

/**
* @return the query part of the uri. For example someparam=32&amp;someotherparam=x
*/
String query();

/** /**
* Set the request host.<p/> * Set the request host.<p/>
* *
Expand Down
Expand Up @@ -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 // 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 // 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; boolean close = false;
// See https://tools.ietf.org/html/rfc7230#section-6.3 // See https://tools.ietf.org/html/rfc7230#section-6.3
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/io/vertx/core/http/impl/HttpClientRequestBase.java
Expand Up @@ -31,14 +31,24 @@ abstract class HttpClientRequestBase implements HttpClientRequest {
private static final Logger log = LoggerFactory.getLogger(HttpClientRequestImpl.class); private static final Logger log = LoggerFactory.getLogger(HttpClientRequestImpl.class);


protected final HttpClientImpl client; 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<Throwable> exceptionHandler; private Handler<Throwable> exceptionHandler;
private long currentTimeoutTimerId = -1; private long currentTimeoutTimerId = -1;
private long lastDataReceived; private long lastDataReceived;
protected boolean exceptionOccurred; protected boolean exceptionOccurred;
private Object metric; private Object metric;


HttpClientRequestBase(HttpClientImpl client) { HttpClientRequestBase(HttpClientImpl client, io.vertx.core.http.HttpMethod method, String host, String uri) {
this.client = client; this.client = client;
this.uri = uri;
this.method = method;
this.host = host;
this.path = HttpUtils.parsePath(uri);
this.query = HttpUtils.parseQuery(uri);
} }


Object metric() { Object metric() {
Expand All @@ -53,6 +63,23 @@ void metric(Object metric) {
protected abstract void doHandleResponse(HttpClientResponseImpl resp); protected abstract void doHandleResponse(HttpClientResponseImpl resp);
protected abstract void checkComplete(); 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 @Override
public HttpClientRequest exceptionHandler(Handler<Throwable> handler) { public HttpClientRequest exceptionHandler(Handler<Throwable> handler) {
synchronized (getLock()) { synchronized (getLock()) {
Expand Down
28 changes: 3 additions & 25 deletions src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java
Expand Up @@ -48,13 +48,9 @@
*/ */
public class HttpClientRequestImpl extends HttpClientRequestBase implements HttpClientRequest { public class HttpClientRequestImpl extends HttpClientRequestBase implements HttpClientRequest {


private final String host;
private final int port;
private final boolean ssl; private final boolean ssl;
private final HttpClientImpl client;
private final VertxInternal vertx; private final VertxInternal vertx;
private final io.vertx.core.http.HttpMethod method; private final int port;
private final String uri;
private Handler<HttpClientResponse> respHandler; private Handler<HttpClientResponse> respHandler;
private Handler<Void> endHandler; private Handler<Void> endHandler;
private boolean chunked; private boolean chunked;
Expand All @@ -76,15 +72,11 @@ public class HttpClientRequestImpl extends HttpClientRequestBase implements Http


HttpClientRequestImpl(HttpClientImpl client, io.vertx.core.http.HttpMethod method, String host, int port, HttpClientRequestImpl(HttpClientImpl client, io.vertx.core.http.HttpMethod method, String host, int port,
boolean ssl, String relativeURI, VertxInternal vertx) { boolean ssl, String relativeURI, VertxInternal vertx) {
super(client); super(client, method, host, relativeURI);
this.host = host;
this.port = port;
this.client = client;
this.chunked = false; this.chunked = false;
this.method = method;
this.vertx = vertx; this.vertx = vertx;
this.uri = relativeURI;
this.ssl = ssl; this.ssl = ssl;
this.port = port;
} }


@Override @Override
Expand Down Expand Up @@ -158,16 +150,6 @@ public String getHost() {
} }
} }


@Override
public io.vertx.core.http.HttpMethod method() {
return method;
}

@Override
public String uri() {
return uri;
}

@Override @Override
public MultiMap headers() { public MultiMap headers() {
synchronized (getLock()) { synchronized (getLock()) {
Expand Down Expand Up @@ -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 // 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 // but there is a catch - the client connection is null before connecting so we synchronized on this before that
// point // point
Expand Down
Expand Up @@ -49,7 +49,7 @@ public HttpClientRequestPushPromise(
String uri, String uri,
String host, String host,
MultiMap headers) throws Http2Exception { MultiMap headers) throws Http2Exception {
super(client); super(client, method, host, uri);
this.handler = handler; this.handler = handler;
this.clientStream = new Http2ClientConnection.Http2ClientStream(handler, this, clientStream); this.clientStream = new Http2ClientConnection.Http2ClientStream(handler, this, clientStream);
this.method = method; this.method = method;
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/vertx/test/core/Http2ClientTest.java
Expand Up @@ -629,7 +629,7 @@ public void testClientResetServerStream() throws Exception {
public void testPushPromise() throws Exception { public void testPushPromise() throws Exception {
waitFor(2); waitFor(2);
server.requestHandler(req -> { server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> { req.response().push(HttpMethod.GET, "/wibble?a=b", ar -> {
assertTrue(ar.succeeded()); assertTrue(ar.succeeded());
HttpServerResponse response = ar.result(); HttpServerResponse response = ar.result();
response.end("the_content"); response.end("the_content");
Expand Down Expand Up @@ -657,7 +657,9 @@ public void testPushPromise() throws Exception {
} }
assertOnIOContext(current); assertOnIOContext(current);
assertEquals(HttpMethod.GET, pushedReq.method()); 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 -> { pushedReq.handler(resp -> {
assertEquals(200, resp.statusCode()); assertEquals(200, resp.statusCode());
Buffer content = Buffer.buffer(); Buffer content = Buffer.buffer();
Expand Down

0 comments on commit 203afee

Please sign in to comment.