Skip to content

Commit

Permalink
fix #278: Resolve the relative location when redirecting
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Feb 12, 2018
1 parent 71e9515 commit 3d7c04f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Expand Up @@ -148,7 +148,7 @@ void redirect(String to) {
String[] redirectedFrom = this.redirectedFrom;
URI from = activeURI;
try {
activeURI = new URI(to);
activeURI = from.resolve(new URI(to));
}
catch (URISyntaxException e) {
throw Exceptions.propagate(e);
Expand Down
53 changes: 53 additions & 0 deletions src/test/java/reactor/ipc/netty/http/client/HttpRedirectTest.java
Expand Up @@ -25,6 +25,7 @@
import reactor.ipc.netty.NettyContext;
import reactor.ipc.netty.http.server.HttpServer;
import reactor.ipc.netty.resources.PoolResources;
import reactor.test.StepVerifier;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -120,4 +121,56 @@ public void testIssue253() {

server.dispose();
}

@Test
public void testIssue278() {
NettyContext server1 =
HttpServer.create(8888)
.newRouter(r -> r.get("/1", (req, res) -> res.sendRedirect("/3"))
.get("/2", (req, res) -> res.sendRedirect("http://localhost:8888/3"))
.get("/3", (req, res) -> res.sendString(Mono.just("OK")))
.get("/4", (req, res) -> res.sendRedirect("http://localhost:8889/1")))
.block(Duration.ofSeconds(30));

NettyContext server2 =
HttpServer.create(8889)
.newRouter(r -> r.get("/1", (req, res) -> res.sendString(Mono.just("Other"))))
.block(Duration.ofSeconds(30));

HttpClient client = HttpClient.create(8888);

Mono<String> response =
client.get("/1", req -> req.followRedirect())
.flatMap(res -> res.receive()
.aggregate()
.asString());

StepVerifier.create(response)
.expectNextMatches(s -> "OK".equals(s))
.expectComplete()
.verify(Duration.ofSeconds(30));

response = client.get("/2", req -> req.followRedirect())
.flatMap(res -> res.receive()
.aggregate()
.asString());

StepVerifier.create(response)
.expectNextMatches(s -> "OK".equals(s))
.expectComplete()
.verify(Duration.ofSeconds(30));

response = client.get("/4", req -> req.followRedirect())
.flatMap(res -> res.receive()
.aggregate()
.asString());

StepVerifier.create(response)
.expectNextMatches(s -> "Other".equals(s))
.expectComplete()
.verify(Duration.ofSeconds(30));

server1.dispose();
server2.dispose();
}
}

0 comments on commit 3d7c04f

Please sign in to comment.