|
| 1 | +/* |
| 2 | + * Jooby https://jooby.io |
| 3 | + * Apache License Version 2.0 https://jooby.io/LICENSE.txt |
| 4 | + * Copyright 2014 Edgar Espina |
| 5 | + */ |
| 6 | +package io.jooby.i3721; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 10 | + |
| 11 | +import java.util.Set; |
| 12 | + |
| 13 | +import io.jooby.ServerOptions; |
| 14 | +import io.jooby.junit.ServerTest; |
| 15 | +import io.jooby.junit.ServerTestRunner; |
| 16 | + |
| 17 | +public class Issue3721 { |
| 18 | + |
| 19 | + @ServerTest |
| 20 | + public void shouldAllowToSetMaxHeaderSize(ServerTestRunner runner) { |
| 21 | + runner |
| 22 | + .define( |
| 23 | + app -> { |
| 24 | + app.setServerOptions(new ServerOptions().setMaxHeaderSize(ServerOptions._16KB)); |
| 25 | + app.get( |
| 26 | + "/3721", |
| 27 | + ctx -> { |
| 28 | + return ctx.header("large").value(); |
| 29 | + }); |
| 30 | + }) |
| 31 | + .ready( |
| 32 | + http -> { |
| 33 | + var large = ".".repeat(ServerOptions._8KB + ServerOptions._4KB); |
| 34 | + http.header("large", large); |
| 35 | + http.get( |
| 36 | + "/3721", |
| 37 | + rsp -> { |
| 38 | + var result = rsp.body().string(); |
| 39 | + assertEquals(large, result); |
| 40 | + assertEquals(ServerOptions._8KB + ServerOptions._4KB, result.length()); |
| 41 | + }); |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + @ServerTest |
| 46 | + public void shouldCheckErrorOnLargeHeaderSize(ServerTestRunner runner) { |
| 47 | + runner |
| 48 | + .define( |
| 49 | + app -> { |
| 50 | + app.setServerOptions(new ServerOptions().setMaxHeaderSize(ServerOptions._4KB)); |
| 51 | + app.get( |
| 52 | + "/3721", |
| 53 | + ctx -> { |
| 54 | + return ctx.header("large").value(); |
| 55 | + }); |
| 56 | + }) |
| 57 | + .ready( |
| 58 | + http -> { |
| 59 | + var large = ".".repeat(ServerOptions._8KB); |
| 60 | + http.header("large", large); |
| 61 | + http.get( |
| 62 | + "/3721", |
| 63 | + rsp -> { |
| 64 | + assertTrue(Set.of(400, 431).contains(rsp.code())); |
| 65 | + }); |
| 66 | + }); |
| 67 | + } |
| 68 | +} |
0 commit comments