Reading body() before or after form() is not consistent across all servers
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #4034 của @jknack — đã merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
The report identifies ctx.body().value() and ctx.form()/ctx.formMap() in a ServerTest that runs against Undertow and Jetty. Start by tracing how each server handles form parsing and body access, then run the supplied test against both servers. Done means the call order behaves consistently across both servers, or the server difference is documented.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I was replacing jooby-undertow with jooby-jetty and I am getting different behaviour due to making a call to ctx.body().value() before ctx.form().toMap()
I expected this to be consistent across different servers, or at least for this difference to be documented.
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby.test;
import io.jooby.exception.MissingValueException;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import java.util.Map;
import okhttp3.FormBody;
import org.junit.jupiter.api.Assertions;
class IssueBodyVsForm {
@ServerTest
public void formDataAndQueryParameters(ServerTestRunner runner) {
runner
.define(
app ->
app.post(
"/",
ctx -> {
try {
Assertions.assertAll(() -> {
Assertions.assertEquals(1, ctx.form().size(), "form contains one entry");
Assertions.assertTrue(ctx.form().isPresent());
Assertions.assertFalse(ctx.form().isMissing());
Assertions.assertEquals("bar", ctx.form().get("foo").value());
Assertions.assertEquals("bar", ctx.form("foo").value());
Assertions.assertEquals("bar", ctx.form().toMap().get("foo"));
Assertions.assertEquals("bar", ctx.formMap().get("foo"));
Assertions.assertEquals("?parameter1=value1", ctx.query().queryString());
Assertions.assertEquals("parameter1=value1", ctx.query().value());
Assertions.assertEquals("value1", ctx.query("parameter1").value());
Assertions.assertEquals("value1", ctx.queryMap().get("parameter1"));
Assertions.assertEquals(1, ctx.queryMap().size());
});
return "OK";
} catch (Exception ex){
ex.printStackTrace();
ctx.setResponseCode(500);
return ex.getMessage();
}
}))
.ready(
http ->
http
.post(
"/",
new FormBody.Builder().add("foo", "bar").build(),
Map.of("parameter1", "value1"),
rsp -> {
Assertions.assertEquals("OK", rsp.body().string());
Assertions.assertEquals(200, rsp.code());
}));
}
@ServerTest
public void readFormDataBeforeBody(ServerTestRunner runner) {
runner
.define(
app ->
app.post(
"/",
ctx -> {
try {
Assertions.assertAll(() -> {
Assertions.assertEquals(1, ctx.form().size(), "form contains one entry");
Assertions.assertTrue(ctx.form().isPresent());
Assertions.assertFalse(ctx.form().isMissing());
Assertions.assertEquals("bar", ctx.form().get("foo").value());
Assertions.assertEquals("bar", ctx.form("foo").value());
Assertions.assertEquals("bar", ctx.form().toMap().get("foo"));
Assertions.assertEquals("bar", ctx.formMap().get("foo"));
// get body().value() after calling form methods
Assertions.assertThrows(MissingValueException.class, () -> ctx.body().value());
});
return "OK";
} catch (Exception ex){
ex.printStackTrace();
ctx.setResponseCode(500);
return ex.getMessage();
}
}))
.ready(
http ->
http
.post(
"/",
new FormBody.Builder().add("foo", "bar").build(),
rsp -> {
Assertions.assertEquals("OK", rsp.body().string());
Assertions.assertEquals(200, rsp.code());
}));
}
@ServerTest
public void readFormDataAfterBody(ServerTestRunner runner) {
runner
.define(
app ->
app.post(
"/",
ctx -> {
try {
Assertions.assertAll(() -> {
// get body().value() before calling form methods
Assertions.assertThrows(MissingValueException.class, () -> ctx.body().value());
Assertions.assertEquals(1, ctx.form().size(), "form contains one entry");
Assertions.assertTrue(ctx.form().isPresent());
Assertions.assertFalse(ctx.form().isMissing());
Assertions.assertEquals("bar", ctx.form().get("foo").value());
Assertions.assertEquals("bar", ctx.form("foo").value());
Assertions.assertEquals("bar", ctx.form().toMap().get("foo"));
Assertions.assertEquals("bar", ctx.formMap().get("foo"));
});
return "OK";
} catch (Exception ex){
ex.printStackTrace();
ctx.setResponseCode(500);
return ex.getMessage();
}
}))
.ready(
http ->
http
.post(
"/",
new FormBody.Builder().add("foo", "bar").build(),
rsp -> {
Assertions.assertEquals("OK", rsp.body().string());
Assertions.assertEquals(200, rsp.code());
}));
}
}
- Ngôn ngữ chính
- Java
- Star
- 1.8k
- Fork
- 207
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của jooby-project/jooby
-
Rainbow Gum logging moduleĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
jooby-project/jooby#4021 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
jooby-project/jooby#3766 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Jooby CLI to SDKMANĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
jooby-project/jooby#3521 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
jooby-1.x are brokenĐang mởquestion
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
jooby-project/jooby#1513 · 10 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của jooby-project/jooby
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug/错误
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
FCL-Team/FoldCraftLauncher#1982 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] micronaut-serde-oracle-jdbc-json brings a second OJDBC driver onto the runtime classpathCó thể đã có người làm @ZARAYACH đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
micronaut-projects/micronaut-serialization#1494 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 2 ngày