forked from eclipse-vertx/vert.x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,8 +60,10 @@ | |
import java.util.function.*; | ||
import java.util.stream.IntStream; | ||
|
||
import static io.vertx.core.http.HttpMethod.GET; | ||
import static io.vertx.core.http.HttpMethod.PUT; | ||
import static io.vertx.test.core.TestUtils.*; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
|
@@ -3726,6 +3728,55 @@ public void testFollowRedirectPutOn308() throws Exception { | |
testFollowRedirect(HttpMethod.PUT, HttpMethod.PUT, 308, 308, 1, "http://" + DEFAULT_HTTP_HOST_AND_PORT + "/redirected", "http://" + DEFAULT_HTTP_HOST_AND_PORT + "/somepath"); | ||
} | ||
|
||
|
||
@Test | ||
public void testFollowRedirectsWithProxy() throws Exception { | ||
Assume.assumeThat("Proxy is only supported with HTTP/1", this, instanceOf(Http1xTest.class)); | ||
waitFor(2); | ||
String location = "http://" + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT + "/ok"; | ||
server.requestHandler(req -> { | ||
if (!req.headers().contains("foo", "bar", true)) { | ||
fail("Missing expected header"); | ||
return; | ||
} | ||
assertEquals(Collections.singletonList("bar"), req.headers().getAll("foo")); | ||
if (req.path().equals("/redirect")) { | ||
req.response().setStatusCode(301).putHeader("Location", location).end(); | ||
} else { | ||
req.response().end(req.path()); | ||
complete(); | ||
} | ||
}); | ||
|
||
startServer(); | ||
startProxy(null, ProxyType.HTTP); | ||
client.request( | ||
new RequestOptions(requestOptions) | ||
.setServer(null) | ||
.setMethod(GET) | ||
.setURI("/redirect") | ||
.setProxyOptions(new ProxyOptions().setPort(proxy.port())) | ||
) | ||
.compose(req -> req | ||
.putHeader("foo", "bar") | ||
.setFollowRedirects(true) | ||
.send() | ||
.compose(resp -> { | ||
assertEquals(200, resp.statusCode()); | ||
assertEquals(location, proxy.getLastUri()); | ||
return resp.body().compose(body -> { | ||
if (resp.statusCode() == 200) { | ||
assertEquals(Buffer.buffer("/ok"), body); | ||
} else { | ||
assertEquals(Buffer.buffer(), body); | ||
} | ||
return Future.succeededFuture(); | ||
}); | ||
}) | ||
).onSuccess(v -> testComplete()); | ||
await(); | ||
} | ||
|
||
private void testFollowRedirect( | ||
HttpMethod method, | ||
HttpMethod expectedMethod, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters