Skip to content
Merged
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
23 changes: 7 additions & 16 deletions src/main/java/io/vertx/httpproxy/impl/ProxiedRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,19 @@
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.*;
import io.vertx.core.internal.ContextInternal;
import io.vertx.core.internal.http.HttpServerRequestInternal;
import io.vertx.core.net.HostAndPort;
import io.vertx.core.streams.Pipe;
import io.vertx.httpproxy.Body;
import io.vertx.httpproxy.MediaType;
import io.vertx.httpproxy.ProxyRequest;
import io.vertx.httpproxy.ProxyResponse;

import java.util.Map;
import java.util.Objects;

import static io.vertx.core.http.HttpHeaders.CONNECTION;
import static io.vertx.core.http.HttpHeaders.CONTENT_LENGTH;
import static io.vertx.core.http.HttpHeaders.KEEP_ALIVE;
import static io.vertx.core.http.HttpHeaders.PROXY_AUTHENTICATE;
import static io.vertx.core.http.HttpHeaders.PROXY_AUTHORIZATION;
import static io.vertx.core.http.HttpHeaders.TRANSFER_ENCODING;
import static io.vertx.core.http.HttpHeaders.UPGRADE;
import static io.vertx.core.http.HttpHeaders.*;

public class ProxiedRequest implements ProxyRequest {

Expand Down Expand Up @@ -152,9 +141,11 @@ public HttpServerRequest proxiedRequest() {

@Override
public ProxyRequest release() {
body.stream().resume();
headers.clear();
body = null;
if (body != null) {
body.stream().resume();
headers.clear();
body = null;
}
return this;
}

Expand Down
41 changes: 26 additions & 15 deletions src/test/java/io/vertx/tests/ProxyRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@
*/
package io.vertx.tests;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.Promise;
import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.RequestOptions;
import io.vertx.core.http.*;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.SocketAddress;
Expand All @@ -40,7 +28,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
Expand Down Expand Up @@ -585,6 +572,30 @@ public void testReleaseProxyRequest(TestContext ctx) {
}));
}

@Test
public void testReleaseProxyRequestAndFail(TestContext ctx) {
SocketAddress backend = startHttpBackend(ctx, 8081, req -> {
ctx.fail("Shouldn't be called");
});
backendClient = vertx.createHttpClient(new HttpClientOptions(clientOptions));
HttpProxy proxy = HttpProxy.reverseProxy(backendClient);
proxy.origin(backend);
proxy.addInterceptor(new ProxyInterceptor() {
@Override
public Future<ProxyResponse> handleProxyRequest(ProxyContext context) {
context.request().release();
return Future.failedFuture("boom");
}
});
startHttpServer(ctx, serverOptions, proxy);
httpClient = vertx.createHttpClient();
httpClient.request(HttpMethod.GET, 8080, "localhost", "/somepath").onComplete(ctx.asyncAssertSuccess(req -> {
req.send().onComplete(ctx.asyncAssertSuccess(resp -> {
ctx.assertEquals(502, resp.statusCode());
}));
}));
}

@Test
public void testSendDefaultProxyResponse(TestContext ctx) {
startHttpServer(ctx, serverOptions, req -> {
Expand Down
Loading