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
8 changes: 5 additions & 3 deletions src/main/java/io/vertx/httpproxy/impl/ProxiedRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,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/httpproxy/ProxyRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,9 @@
*/
package io.vertx.httpproxy;

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.HttpClientRequest;
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 Down Expand Up @@ -579,6 +566,30 @@ public void testReleaseProxyRequest(TestContext ctx) {
}));
}

@Test
public void testReleaseProxyRequestAndFail(TestContext ctx) {
SocketAddress backend = startHttpBackend(ctx, 8081, req -> {
ctx.fail("Shouldn't be called");
});
HttpClient 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 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