|
| 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.i4053; |
| 7 | + |
| 8 | +import static io.jooby.test.TestUtil._16kb; |
| 9 | +import static io.jooby.test.TestUtil._19kb; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | + |
| 14 | +import io.jooby.ServerOptions; |
| 15 | +import io.jooby.junit.ServerTest; |
| 16 | +import io.jooby.junit.ServerTestRunner; |
| 17 | +import okhttp3.MediaType; |
| 18 | +import okhttp3.RequestBody; |
| 19 | +import okio.BufferedSink; |
| 20 | + |
| 21 | +public class Issue4053 { |
| 22 | + |
| 23 | + @ServerTest |
| 24 | + public void maxRequestSizeAppliesToChunkedBody(ServerTestRunner runner) { |
| 25 | + runner |
| 26 | + .options(new ServerOptions().setMaxRequestSize(ServerOptions._16KB)) |
| 27 | + .define(app -> app.post("/4053", ctx -> ctx.body().value(""))) |
| 28 | + .ready( |
| 29 | + client -> { |
| 30 | + client.post( |
| 31 | + "/4053", |
| 32 | + chunked(_19kb), |
| 33 | + rsp -> { |
| 34 | + assertEquals(413, rsp.code()); |
| 35 | + }); |
| 36 | + client.post( |
| 37 | + "/4053", |
| 38 | + chunked(_16kb), |
| 39 | + rsp -> { |
| 40 | + assertEquals(200, rsp.code()); |
| 41 | + assertEquals(_16kb, rsp.body().string()); |
| 42 | + }); |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + // OkHttp sends a body of unknown length with Transfer-Encoding: chunked. |
| 47 | + private static RequestBody chunked(String value) { |
| 48 | + return new RequestBody() { |
| 49 | + @Override |
| 50 | + public MediaType contentType() { |
| 51 | + return MediaType.get("text/plain"); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public long contentLength() { |
| 56 | + return -1; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public void writeTo(BufferedSink sink) throws IOException { |
| 61 | + sink.writeUtf8(value); |
| 62 | + } |
| 63 | + }; |
| 64 | + } |
| 65 | +} |
0 commit comments