diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-05-20 22:38:10 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-05-20 22:40:52 +0200 |
commit | 9da0af1113fde3df1add0ea53d89b4a501f2588e (patch) | |
tree | 972b9c9f12758752287ce50e313427b56bccd8f5 | |
parent | 844d55001449f261c6f2de1ff059a606932a50ca (diff) |
nxt_unit_app_test.c: Test if nxt_unit_response_add_content(3) can be called several times
It can.
$ echo -e 'GET / HTTP/1.1\r\nHost: _\n' | ncat localhost 80;
HTTP/1.1 200 OK
Content-Type: text/plain
Server: Unit/1.30.0
Date: Sat, 20 May 2023 20:38:04 GMT
Transfer-Encoding: chunked
9b
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: _
15
But send this first.
15
Some extra contents.
e
And some more
0
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | src/nxt_unit_app_test.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nxt_unit_app_test.c b/src/nxt_unit_app_test.c index a5dc1aa..62fef41 100644 --- a/src/nxt_unit_app_test.c +++ b/src/nxt_unit_app_test.c @@ -19,7 +19,6 @@ #define CONTENT_TYPE "Content-Type" #define TEXT_PLAIN "text/plain" -#define HELLO_WORLD "Hello world!\n" #define NEW_LINE "\n" @@ -160,7 +159,7 @@ greeting_app_request_handler(nxt_unit_request_info_t *req) 1 /* Number of response headers. */, nxt_length(CONTENT_TYPE) + nxt_length(TEXT_PLAIN) - + nxt_length(HELLO_WORLD)); + + nxt_length("Hello world\n!")); if (nxt_slow_path(rc != NXT_UNIT_OK)) { goto fail; } @@ -172,8 +171,12 @@ greeting_app_request_handler(nxt_unit_request_info_t *req) goto fail; } - rc = nxt_unit_response_add_content(req, HELLO_WORLD, - nxt_length(HELLO_WORLD)); + rc = nxt_unit_response_add_content(req, "Hello", nxt_length("Hello")); + if (nxt_slow_path(rc != NXT_UNIT_OK)) { + goto fail; + } + rc = nxt_unit_response_add_content(req, " world!\n", + nxt_length(" world!\n")); if (nxt_slow_path(rc != NXT_UNIT_OK)) { goto fail; } |