From 8450ae0d10db8f88b597a329b1c32ba7df6c1642 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Sun, 19 Apr 2026 20:32:23 +0200 Subject: [PATCH] test: codify body-framing cases (RFC 9110 section 8.6 and RFC 9112 section 6.1) --- .../rfc9110_body_framing_get_cl_nonzero_01.http | 5 +++++ .../rfc9110_body_framing_get_cl_nonzero_01.py | 16 ++++++++++++++++ .../rfc9110_body_framing_get_cl_zero_01.http | 4 ++++ .../valid/rfc9110_body_framing_get_cl_zero_01.py | 15 +++++++++++++++ .../valid/rfc9110_body_framing_http10_cl_01.http | 5 +++++ .../valid/rfc9110_body_framing_http10_cl_01.py | 16 ++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.http create mode 100644 tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.py create mode 100644 tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.http create mode 100644 tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.py create mode 100644 tests/requests/valid/rfc9110_body_framing_http10_cl_01.http create mode 100644 tests/requests/valid/rfc9110_body_framing_http10_cl_01.py diff --git a/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.http b/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.http new file mode 100644 index 00000000..58e4b571 --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.http @@ -0,0 +1,5 @@ +GET /foo HTTP/1.1\r\n +Host: example.com\r\n +Content-Length: 5\r\n +\r\n +hello diff --git a/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.py b/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.py new file mode 100644 index 00000000..61ab85d2 --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_get_cl_nonzero_01.py @@ -0,0 +1,16 @@ +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. + +# RFC 9110 section 8.6: a GET with a non-zero Content-Length is +# "discouraged" but not forbidden; the body must be preserved. +request = { + "method": "GET", + "uri": uri("/foo"), + "version": (1, 1), + "headers": [ + ("HOST", "example.com"), + ("CONTENT-LENGTH", "5"), + ], + "body": b"hello", +} diff --git a/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.http b/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.http new file mode 100644 index 00000000..b237bc34 --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.http @@ -0,0 +1,4 @@ +GET /foo HTTP/1.1\r\n +Host: example.com\r\n +Content-Length: 0\r\n +\r\n diff --git a/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.py b/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.py new file mode 100644 index 00000000..9a3c7f64 --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_get_cl_zero_01.py @@ -0,0 +1,15 @@ +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. + +# RFC 9110 section 8.6: Content-Length: 0 on GET is valid. +request = { + "method": "GET", + "uri": uri("/foo"), + "version": (1, 1), + "headers": [ + ("HOST", "example.com"), + ("CONTENT-LENGTH", "0"), + ], + "body": b"", +} diff --git a/tests/requests/valid/rfc9110_body_framing_http10_cl_01.http b/tests/requests/valid/rfc9110_body_framing_http10_cl_01.http new file mode 100644 index 00000000..35c03289 --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_http10_cl_01.http @@ -0,0 +1,5 @@ +POST /foo HTTP/1.0\r\n +Host: example.com\r\n +Content-Length: 5\r\n +\r\n +hello diff --git a/tests/requests/valid/rfc9110_body_framing_http10_cl_01.py b/tests/requests/valid/rfc9110_body_framing_http10_cl_01.py new file mode 100644 index 00000000..9afc362e --- /dev/null +++ b/tests/requests/valid/rfc9110_body_framing_http10_cl_01.py @@ -0,0 +1,16 @@ +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. + +# RFC 9112 section 6.1: Content-Length is the only framing option for +# HTTP/1.0 bodies (chunked was added in HTTP/1.1). +request = { + "method": "POST", + "uri": uri("/foo"), + "version": (1, 0), + "headers": [ + ("HOST", "example.com"), + ("CONTENT-LENGTH", "5"), + ], + "body": b"hello", +}