src/server/test/io.c

Tue, 24 Feb 2026 12:28:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 24 Feb 2026 12:28:58 +0100
changeset 702
ee80191310ca
parent 660
f00d03835dd9
permissions
-rw-r--r--

fix build on Solaris 10

498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "io.h"
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "testutils.h"
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
702
ee80191310ca fix build on Solaris 10
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 660
diff changeset
33 #include <limits.h>
ee80191310ca fix build on Solaris 10
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 660
diff changeset
34
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
36 CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_first) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 char *str = strdup("100\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 char *str2 = strdup("12345\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 size_t len2 = strlen(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 char *str3 = strdup("FF\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 size_t len3 = strlen(str3);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
44 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
46 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
47 int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
48 CX_TEST_ASSERT(ret == 5);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
49 CX_TEST_ASSERT(chunklen == 0x100);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
50
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
51 // test 2
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
52 ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
53 CX_TEST_ASSERT(ret == 7);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
54 CX_TEST_ASSERT(chunklen == 0x12345);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
55
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
56 // test 3: hex test
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
57 ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
58 CX_TEST_ASSERT(ret == 4);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
59 CX_TEST_ASSERT(chunklen == 0xFF);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
61 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 free(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
66 CX_TEST(test_io_http_stream_parse_chunk_header_hdronly) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 char *str = strdup("\r\n100\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 char *str2 = strdup("\nab\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 size_t len2 = strlen(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
72 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
74 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
75 int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
76 CX_TEST_ASSERT(ret == 7);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
77 CX_TEST_ASSERT(chunklen == 0x100);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
78
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
79 // test 2 with just \n as line break
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
80 ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
81 CX_TEST_ASSERT(ret == 4);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
82 CX_TEST_ASSERT(chunklen == 0xab);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
84 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 free(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
89 CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_seq_fail) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 // test: after the first chunk header, \r\n is required before any new header
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 char *str = strdup("ff\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
94 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
96 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
97 int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
98 CX_TEST_ASSERT(ret == -1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
100 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
104 CX_TEST(test_io_http_stream_parse_chunk_header_hdr_data) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 char *str = strdup("\r\nb\r\nhello world\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
108 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
110 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
111 int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
112 CX_TEST_ASSERT(ret == 5);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
114 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
118 CX_TEST(test_io_http_stream_parse_chunk_header_empty) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 char *str = "";
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
122 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
124 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
125 int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
126 CX_TEST_ASSERT(ret == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
127
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
128 ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
129 CX_TEST_ASSERT(ret == 0);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
131 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
134 CX_TEST(test_io_http_stream_parse_chunk_header_partial_first) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 char *str = strdup("123");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
138 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
140 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
141 int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
142 CX_TEST_ASSERT(ret == 0);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
144 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
148 CX_TEST(test_io_http_stream_parse_chunk_header_partial) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 char *str = strdup("123");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 char *str2 = strdup("\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 size_t len2 = strlen(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 char *str3 = strdup("\r");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 size_t len3 = strlen(str3);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 char *str4 = strdup("\r\n123");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 size_t len4 = strlen(str4);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
158 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
160 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
161 int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
162 CX_TEST_ASSERT(ret == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
163 ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
164 CX_TEST_ASSERT(ret == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
165 ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
166 CX_TEST_ASSERT(ret == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
167 ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
168 CX_TEST_ASSERT(ret == 0);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
170 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 free(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 free(str3);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 free(str4);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
177 CX_TEST(test_io_http_stream_parse_chunk_header_invalid) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 char *str = strdup("hello\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 char *str2 = strdup("x4\r\n\r\n123\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 size_t len2 = strlen(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 char *str3 = strdup("\r\n\r\n123\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 size_t len3 = strlen(str3);
550
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
184 char *str4 = strdup("\r\n\r\nx123\r\n");
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
185 size_t len4 = strlen(str3);
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
186 char *str5 = strdup("\r\n\r\n1 2 3\r\n");
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
187 size_t len5 = strlen(str3);
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
188 char *str6 = strdup("\r\n\r\n1 23\r\n");
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
189 size_t len6 = strlen(str3);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
191 CX_TEST_DO {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
192 int64_t chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
193 int ret;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
194
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
195 ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
196 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
197 ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
198 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
199
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
200 ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
201 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
202 ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
203 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
204
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
205 ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
206 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
207 ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
208 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
209
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
210 ret = http_stream_parse_chunk_header(str4, len4, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
211 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
212 ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
213 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
214
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
215 ret = http_stream_parse_chunk_header(str5, len5, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
216 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
217 ret = http_stream_parse_chunk_header(str5, len5, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
218 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
219
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
220 ret = http_stream_parse_chunk_header(str6, len6, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
221 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
222 ret = http_stream_parse_chunk_header(str6, len6, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
223 CX_TEST_ASSERT(ret == -1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
224 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 free(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 free(str3);
550
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
229 free(str4);
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
230 free(str5);
77241b3ba544 add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 549
diff changeset
231 free(str6);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
234 CX_TEST(test_io_http_stream_parse_chunk_header_zero) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 char *str = strdup("\r\n0\r\n\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 size_t len = strlen(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 char *str2 = strdup("0\r\n\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 size_t len2 = strlen(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 // incomplete
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 char *str3 = strdup("\r\n0\r\n");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 size_t len3 = strlen(str3);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 char *str4 = strdup("\r\n0");
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 size_t len4 = strlen(str4);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
247 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
249 int64_t chunklen = -1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
250 int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
251 CX_TEST_ASSERT(ret == 7);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
252 CX_TEST_ASSERT(chunklen == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
253
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
254 chunklen = -1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
255 ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
256 CX_TEST_ASSERT(ret == 5);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
257 CX_TEST_ASSERT(chunklen == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
258
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
259 // expect 0 (incomplete)
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
260 ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
261 CX_TEST_ASSERT(ret == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
262
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
263 ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
264 CX_TEST_ASSERT(ret == 0);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
266 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 free(str);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 free(str2);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 free(str3);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 free(str4);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
274 CX_TEST(test_io_httpstream_write) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
280 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
282 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
283 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
284
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
285 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
286
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
287 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
288 CX_TEST_ASSERT(st->buf->size == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
289 CX_TEST_ASSERT(!memcmp(st->buf->space, msg, msglen));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
290
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
291 // test again, make sure the second message is written directly after the wirst one
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
292 char *msg2 = "test";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
293 size_t msglen2 = strlen(msg2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
294
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
295 w = net_write(http, msg2, msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
296
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
297 CX_TEST_ASSERT(w == msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
298 CX_TEST_ASSERT(st->buf->size == msglen+msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
299 CX_TEST_ASSERT(!memcmp(st->buf->space + msglen, msg2, msglen2));
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
301 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 testutil_destroy_session(sn);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
306 CX_TEST(test_io_httpstream_chunked_write) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 httpstream_enable_chunked_write(http);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
313 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
315 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
316 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
317
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
318 char *bufmsg = "c\r\nhello world!\r\n";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
319 size_t bufmsglen = strlen(bufmsg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
320
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
321 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
322
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
323 cxstring s1 = cx_strn(st->buf->space, st->buf->size);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
324 cxstring s2 = cx_strn(bufmsg, bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
325
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
326 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
327 CX_TEST_ASSERT(st->buf->size == bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
328 CX_TEST_ASSERT(!cx_strcasecmp(s1, s2));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
329
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
330 // write again
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
331 w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
332 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
333 CX_TEST_ASSERT(st->buf->size == 2*bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
334
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
335 cxstring s3 = cx_strn(st->buf->space+bufmsglen, bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
336 CX_TEST_ASSERT(!cx_strcasecmp(s2, s3));
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
338 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
341 CX_TEST(test_io_httpstream_chunked_write_end) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 httpstream_enable_chunked_write(http);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
348 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
350 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
351 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
352
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
353 char *bufmsg = "c\r\nhello world!\r\n0\r\n\r\n";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
354 size_t bufmsglen = strlen(bufmsg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
355
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
356 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
357 net_finish(http);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
358
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
359 cxstring s1 = cx_strn(st->buf->space, st->buf->size);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
360 cxstring s2 = cx_strn(bufmsg, bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
361
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
362 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
363 CX_TEST_ASSERT(st->buf->size == bufmsglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
364 CX_TEST_ASSERT(!cx_strcasecmp(s1, s2));
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
366 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
369 CX_TEST(test_io_httpstream_chunked_write_xx) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 // This test creates a giant buffer and writes it with
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 // chunked transfer encoding to the http stream with varying chunk length
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 httpstream_enable_chunked_write(http);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
379 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
381 // create test data
660
f00d03835dd9 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 633
diff changeset
382 CxBuffer *testdata = cxBufferCreate(cxDefaultAllocator, NULL, 1024*1024*4, 0);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
383 for(size_t i=0;i<testdata->capacity;i++) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
384 cxBufferPut(testdata, 35+(i%91));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
385 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
386
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
387 // write chunks, start with single diget chunk length and increase
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
388 // chunk size with each step
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
389 size_t pos = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
390 int j = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
391 ssize_t i=15;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
392 while(pos<testdata->size) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
393 char *buf = testdata->space + pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
394 size_t remaining = testdata->size - pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
395 ssize_t len = pos + i < remaining ? i : remaining;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
396 pos += len;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
397
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
398 ssize_t w = net_write(http, buf, len);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
399
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
400 CX_TEST_ASSERT(w == len);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
401 i+=100; // increase chunk size
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
402 j++; // debug
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 }
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
404
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
405 // terminate chunk
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
406 net_finish(http);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
407
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
408 // code below also used in test_io_httpstream_chunked_write_xx_limit
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
409
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
410 // make sure the output is correctly encoded
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
411 // extract chunks from st->buf by using http_stream_parse_chunk_header
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
412 // (which should be well-tested)
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
413 WSBool first_chunk = TRUE;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
414 int64_t chunklen = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
415
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
416 char *buf = st->buf->space;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
417 size_t bufsize = st->buf->size;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
418
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
419 pos = 0; // st->buf position
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
420 size_t srcpos = 0; // testdata position
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
421 int debug_counter = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
422 while(pos < bufsize) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
423 ssize_t remaining = bufsize - pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
424 ssize_t src_remaining = testdata->size - srcpos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
425
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
426 int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
427 first_chunk = FALSE;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
428
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
429 // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax)
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
430 CX_TEST_ASSERT(ret > 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
431 if(chunklen == 0) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
432 CX_TEST_ASSERT(src_remaining == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
433 break;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
434 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
435
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
436 CX_TEST_ASSERT(chunklen <= src_remaining);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
437
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
438 char *src_chunk = testdata->space+srcpos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
439 char *buf_chunk = buf+pos+ret;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
440
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
441 CX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
442
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
443 pos += ret + chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
444 srcpos += chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
445
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
446 debug_counter++;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
447 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
448
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
449 cxBufferFree(testdata);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
450 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
451 testutil_iostream_destroy(st);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
452
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
456 CX_TEST(test_io_httpstream_chunked_write_partial_header) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
457 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 httpstream_enable_chunked_write(http);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
462
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
463 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 memset(st->buf->space, 0, st->buf->capacity);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 char *msg = "hello world!";
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 size_t msglen = strlen(msg);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 st->max_write = 1; // limit the test stream max write size
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 498
diff changeset
471 io_set_max_writes(1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 // only 1 byte of the header is written, 0 bytes of msg
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 ssize_t w = net_write(http, msg, msglen);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
475 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
476 CX_TEST_ASSERT(st->buf->size == 1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
477 CX_TEST_ASSERT(tolower(st->buf->space[0]) == 'c');
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 // next header byte: '\r'
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 w = net_write(http, msg, msglen);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
481 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
482 CX_TEST_ASSERT(st->buf->size == 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
483 CX_TEST_ASSERT(st->buf->space[1] == '\r');
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 // next header byte: '\n'
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 w = net_write(http, msg, msglen);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
487 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
488 CX_TEST_ASSERT(st->buf->size == 3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
489 CX_TEST_ASSERT(st->buf->space[2] == '\n');
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 // next: content
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 w = net_write(http, msg, msglen);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
493 CX_TEST_ASSERT(w == 1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
494 CX_TEST_ASSERT(st->buf->size == 4);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
495 CX_TEST_ASSERT(st->buf->space[3] == msg[0]);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 testutil_destroy_session(sn);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 testutil_iostream_destroy(st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
500 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
503 CX_TEST(test_io_httpstream_chunked_write_partial_data) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 httpstream_enable_chunked_write(http);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
510 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
512 memset(st->buf->space, 0, st->buf->capacity);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
513
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
514 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
515 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
516 size_t msglen_orig = msglen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
517
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
518 // limit first write to 3 to only write the header
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
519 st->max_write = 3;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
520 io_set_max_writes(1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
521
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
522 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
523
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
524 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
525 CX_TEST_ASSERT(st->buf->size == 3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
526 CX_TEST_ASSERT(st->buf->space[0] == 'c');
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
527 CX_TEST_ASSERT(st->buf->space[2] == '\n');
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
528
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
529 w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
530 CX_TEST_ASSERT(w == 3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
531 CX_TEST_ASSERT(st->buf->size == 6);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
532 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhel\0", 7));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
533
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
534 msg += w;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
535 msglen -= w;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
536
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
537 w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
538 CX_TEST_ASSERT(w == 3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
539 CX_TEST_ASSERT(st->buf->size == 9);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
540 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello \0", 10));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
541
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
542 st->max_write = 1024;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
543 msg += w;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
544 msglen -= w;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
545
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
546 w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
547 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
548 CX_TEST_ASSERT(st->buf->size == 3 + msglen_orig + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
549 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n", st->buf->size));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
550
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
551 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
552 testutil_iostream_destroy(st);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
554 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
557 CX_TEST(test_io_httpstream_chunked_write_partial_trailer) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
558 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
559
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
560 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
562 httpstream_enable_chunked_write(http);
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 498
diff changeset
563 io_set_max_writes(1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
564
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
565 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
566
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
567 memset(st->buf->space, 0, st->buf->capacity);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
568
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
569 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
570 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
571
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
572 char *msg2 = "newmsg";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
573 size_t msglen2 = strlen(msg2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
574
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
575 char *msg3 = "msg3";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
576 size_t msglen3 = strlen(msg3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
577
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
578 st->max_write = 3 + msglen; // header + msg, but without trailer
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
579
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
580 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
581
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
582 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
583 CX_TEST_ASSERT(st->buf->size == 3 + msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
584 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
585
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
586 st->max_write = 2 + 3 + msglen2; // trailer + new header + new msg, without new trailer
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
587
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
588 w = net_write(http, msg2, msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
589 CX_TEST_ASSERT(w == msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
590 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
591 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
592
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
593 // limit write to 1 byte: two writes required for trailer, net_write should return 0
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
594 st->max_write = 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
595
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
596 w = net_write(http, "dummymsg", 8);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
597 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
598
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
599 w = net_write(http, "dummymsg", 8);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
600 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
601 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
602 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
603
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
604 st->max_write = 1024;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
605 w = net_write(http, msg3, msglen3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
606
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
607 CX_TEST_ASSERT(w == msglen3);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
608 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2 + 3 + msglen3 + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
609 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n4\r\nmsg3\r\n", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
610
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
611
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
612 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
613 testutil_iostream_destroy(st);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
615 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
617
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
618 CX_TEST(test_io_httpstream_chunked_write_partial_trailer_partial_header) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
619 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
621 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
622 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 httpstream_enable_chunked_write(http);
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 498
diff changeset
624 io_set_max_writes(1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
626 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
627
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
628 memset(st->buf->space, 0, st->buf->capacity);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
629
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
630 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
631 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
632
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
633 char *msg2 = "newmsg";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
634 size_t msglen2 = strlen(msg2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
635
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
636 // Test: write partial trailer followed by partial header write
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
637
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
638 st->max_write = 3 + msglen + 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
639
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
640 ssize_t w = net_write(http, msg, msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
641
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
642 CX_TEST_ASSERT(w == msglen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
643 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
644 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
645
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
646 st->max_write = 2; // write 1 trailer byte and 1 header byte
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
647
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
648 w = net_write(http, msg2, msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
649
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
650 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
651 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
652 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
653
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
654 // force partial header write again
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
655 st->max_write = 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
656
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
657 w = net_write(http, msg2, msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
658
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
659 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
660 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
661 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\0", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
662
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
663 st->max_write = 1024;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
664
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
665 w = net_write(http, msg2, msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
666
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
667 CX_TEST_ASSERT(w ==msglen2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
668 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
669 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
670
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
671
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
672 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
673 testutil_iostream_destroy(st);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
674
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
675 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
676 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
677
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
678 CX_TEST(test_io_httpstream_chunked_write_data_2x) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
679 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
680
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
681 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
682 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
683 httpstream_enable_chunked_write(http);
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 498
diff changeset
684 io_set_max_writes(1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
685
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
686 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
687
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
688 memset(st->buf->space, 0, st->buf->capacity);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
689
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
690 // Test: First write a partial header, which forces a chunk with a specific
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
691 // size. After that, write a message, that is bigger than the first
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
692 // chunk, forcing a start of a second chunk, in one big writev op.
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
693
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
694 char *msg = "hello world!";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
695 size_t msglen = strlen(msg);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
696
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
697 char *msg2 = "newmsg";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
698 size_t msglen2 = strlen(msg2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
699
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
700 char *msg_big = "hello world!newmsg";
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
701 size_t msglen_big = strlen(msg_big);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
702
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
703 st->max_write = 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
704
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
705 ssize_t w = net_write(http, msg, msglen); // first chunk: msg
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
706
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
707 CX_TEST_ASSERT(w == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
708 CX_TEST_ASSERT(st->buf->size == 1);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
709
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
710 st->max_write = 1024;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
711
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
712 w = net_write(http, msg_big, msglen_big); // first chunk + new chunk
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
713
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
714 CX_TEST_ASSERT(w == msglen_big);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
715 CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
716 CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
717
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
718
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
719 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
720 testutil_iostream_destroy(st);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
721
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
722 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
723 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
724
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
725 CX_TEST(test_io_httpstream_chunked_write_xx_limit) {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
726 Session *sn = testutil_session();
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
727
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
728 TestIOStream *st = testutil_iostream(2048, TRUE);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
729 IOStream *http = httpstream_new(sn->pool, (IOStream*)st);
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
730 httpstream_enable_chunked_write(http);
513
9a49c245a49c change net_write to attempt to write all bytes, improve error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 498
diff changeset
731 io_set_max_writes(1);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
732
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
733 CX_TEST_DO {
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
734
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
735 // Test: create testdata and write it in varying chunk sizes, but
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
736 // limit TestIOStream to 1 to 3 byte writes
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
737
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
738 // create test data
660
f00d03835dd9 update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 633
diff changeset
739 CxBuffer *testdata = cxBufferCreate(cxDefaultAllocator, NULL, 1024*16, 0);
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
740 for(size_t i=0;i<testdata->capacity;i++) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
741 cxBufferPut(testdata, 35+(i%91));
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
742 }
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
743
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
744 st->max_write = 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
745
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
746 size_t pos = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
747 int chunksize = 1;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
748 while(pos < testdata->size) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
749 size_t available = testdata->size - pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
750
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
751 char *chunk = testdata->space + pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
752 size_t chunklen = chunksize > available ? available : chunksize;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
753
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
754 // write chunk
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
755 size_t chunkpos = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
756 int max_writes = chunklen + 24; // max number of write attempts
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
757 int writes = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
758 while(chunkpos < chunklen) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
759 ssize_t w = net_write(http, chunk+chunkpos, chunklen-chunkpos);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
760 CX_TEST_ASSERT(w >= 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
761 chunkpos += w;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
762
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
763 writes++;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
764 CX_TEST_ASSERT(writes < max_writes);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
765 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
766
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
767 pos += chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
768 chunksize += 5;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
769
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
770 // increase max write size at some point
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
771 if(pos + chunksize >= testdata->size) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
772 st->max_write = INT_MAX;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
773 } else if(pos > 1024*2) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
774 if(pos < 1024*8) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
775 st->max_write = 2;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
776 } else {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
777 st->max_write = 3;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
778 }
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
779 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
780 }
633
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
781
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
782 // terminate chunk
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
783 net_finish(http);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
784
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
785
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
786 // same code as test_io_httpstream_chunked_write_xx
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
787
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
788 // make sure the output is correctly encoded
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
789 // extract chunks from st->buf by using http_stream_parse_chunk_header
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
790 // (which should be well-tested)
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
791
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
792 WSBool first_chunk = TRUE;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
793 int64_t chunklen = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
794
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
795 char *buf = st->buf->space;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
796 size_t bufsize = st->buf->size;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
797
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
798 pos = 0; // st->buf position
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
799 size_t srcpos = 0; // testdata position
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
800 int debug_counter = 0;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
801 while(pos < bufsize) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
802 ssize_t remaining = bufsize - pos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
803 ssize_t src_remaining = testdata->size - srcpos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
804
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
805 int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
806 first_chunk = FALSE;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
807
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
808 // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax)
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
809 CX_TEST_ASSERT(ret > 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
810 if(chunklen == 0) {
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
811 CX_TEST_ASSERT(src_remaining == 0);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
812 break;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
813 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
814
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
815 CX_TEST_ASSERT(chunklen <= src_remaining);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
816
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
817 char *src_chunk = testdata->space+srcpos;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
818 char *buf_chunk = buf+pos+ret;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
819
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
820 CX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen));
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
821
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
822 pos += ret + chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
823 srcpos += chunklen;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
824
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
825 debug_counter++;
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
826 }
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
827
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
828
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
829 testutil_destroy_session(sn);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
830 testutil_iostream_destroy(st);
392ec9026b07 port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
831 cxBufferFree(testdata);
498
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
832
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
833 }
0d80f8a2b29f fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
834 }

mercurial