Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Reading body() before or after form() is not consistent across all servers

クローズ
#4,031 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #4034 @jknack による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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());
                        }));
  }
}
主要言語
Java
スター
1.8k
フォーク
207
平均マージ
1日 8時間
マージ済み PR(30日)
20

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jooby-project/jooby のほかの issue

jooby-project/jooby の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。