ratpack / ratpack

Lean & powerful HTTP apps
https://ratpack.io
Other
1.94k stars 395 forks source link

Paths are not binded when handlers added dynamically with ctx.insert #1337

Open matejuh opened 6 years ago

matejuh commented 6 years ago

This test case fails although it should pass:

import org.junit.Assert;
import ratpack.handling.Handler;
import ratpack.handling.Handlers;
import ratpack.test.embed.EmbeddedApp;

public class Server {
    public static void main(String... args) throws Exception {
        EmbeddedApp.of(s -> s
                .handlers(c -> c.get(":a/:b", ctx -> {
                            Handler h = Handlers.path(":a/:b", ctx1 -> {
                                ctx.getResponse().status(204).send();
                            });
                            ctx.insert(h);
                        })
                )).test(httpClient ->
                Assert.assertEquals(204, httpClient.get("/1/2").getStatusCode()));
    }
}

I think this is wrong because then pastBinding here is an empty string so it will never match.

colombia9503 commented 6 years ago

Remove the .send() from the h Handler. it might thrown a double transmission error with that send