From 1f4e42b7c240a785f09c1d3226aed7e931b20cbc Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 20 May 2023 23:04:43 +0200 Subject: nxt_unit_app_test.c: Test what happens if we lie in the Content-Length 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 --- src/nxt_unit_app_test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3