summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-05-20 23:04:43 +0200
committerAlejandro Colomar <alx@kernel.org>2023-05-20 23:05:14 +0200
commit1f4e42b7c240a785f09c1d3226aed7e931b20cbc (patch)
treece56d9a28d83eabdcad5f28b32fdc837ea67b517
parent98e576518114dd78dbb90a00ee42988f0106b600 (diff)
nxt_unit_app_test.c: Test what happens if we lie in the Content-LengthHEADmain
As expected, Unit just sends what you said: $ echo -e 'GET / HTTP/1.1\r\nHost: _\n' | ncat localhost 80; HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 42 Server: Unit/1.30.0 Date: Sat, 20 May 2023 21:05:06 GMT Hello world! Request data: Method: GET Protocol: HTTP/1.1 Remote addr: 127.0.0.1 Local addr: 127.0.0.1 Target: / Path: / Fields: Host: _ But send this first. Some extra contents. And some more Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--src/nxt_unit_app_test.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/nxt_unit_app_test.c b/src/nxt_unit_app_test.c
index 886a31d..9233513 100644
--- a/src/nxt_unit_app_test.c
+++ b/src/nxt_unit_app_test.c
@@ -155,9 +155,11 @@ greeting_app_request_handler(nxt_unit_request_info_t *req)
nxt_unit_request_t *r;
rc = nxt_unit_response_init(req, 200 /* Status code. */,
- 1 /* Number of response headers. */,
+ 2 /* Number of response headers. */,
strlen(CONTENT_TYPE)
+ strlen(TEXT_PLAIN)
+ + strlen("Content-Length")
+ + strlen("42")
+ strlen("Hello world\n!"));
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
goto fail;
@@ -170,6 +172,13 @@ greeting_app_request_handler(nxt_unit_request_info_t *req)
goto fail;
}
+ rc = nxt_unit_response_add_field(req,
+ "Content-Length", strlen("Content-Length"),
+ "42", strlen("42"));
+ if (nxt_slow_path(rc != NXT_UNIT_OK)) {
+ goto fail;
+ }
+
rc = nxt_unit_response_add_content(req, "Hello", strlen("Hello"));
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
goto fail;