Sat, 22 Nov 2025 14:27:01 +0100
port old ucx2 tests to ucx3
|
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 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
34 | 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
|
35 | 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
|
36 | 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
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | 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
|
41 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
42 | 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
|
43 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
44 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
45 | 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
|
46 | CX_TEST_ASSERT(ret == 5); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
47 | CX_TEST_ASSERT(chunklen == 0x100); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
48 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
49 | // test 2 |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
50 | 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
|
51 | CX_TEST_ASSERT(ret == 7); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
52 | CX_TEST_ASSERT(chunklen == 0x12345); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
53 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
54 | // test 3: hex test |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
55 | 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
|
56 | CX_TEST_ASSERT(ret == 4); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
57 | 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
|
58 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
59 | } |
|
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 | 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
|
61 | 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
|
62 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
64 | 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
|
65 | 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
|
66 | 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
|
67 | 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
|
68 | 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
|
69 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
70 | 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
|
71 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
72 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
73 | 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
|
74 | CX_TEST_ASSERT(ret == 7); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
75 | CX_TEST_ASSERT(chunklen == 0x100); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
76 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
77 | // 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
|
78 | 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
|
79 | CX_TEST_ASSERT(ret == 4); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
80 | 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
|
81 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
82 | } |
|
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 | 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
|
84 | 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
|
85 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
87 | 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
|
88 | // 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
|
89 | 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
|
90 | 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
|
91 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
92 | 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
|
93 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
94 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
95 | 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
|
96 | 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
|
97 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
98 | } |
|
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 | 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
|
100 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
106 | 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
|
107 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
108 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
109 | 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
|
110 | 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
|
111 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
112 | } |
|
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 | 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
|
114 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
116 | 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
|
117 | 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
|
118 | 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
|
119 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
120 | 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
|
121 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
122 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
123 | 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
|
124 | CX_TEST_ASSERT(ret == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
125 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
126 | 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
|
127 | 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
|
128 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
129 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
132 | 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
|
133 | 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
|
134 | 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
|
135 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
136 | 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
|
137 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
138 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
139 | 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
|
140 | 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
|
141 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
142 | } |
|
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 | 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
|
144 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
156 | 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
|
157 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
158 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
159 | 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
|
160 | CX_TEST_ASSERT(ret == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
161 | 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
|
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(str3, len3, 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(str4, len4, 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); |
|
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
|
167 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
168 | } |
|
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 | 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
|
170 | 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
|
171 | 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
|
172 | 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
|
173 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
175 | 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
|
176 | 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
|
177 | 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
|
178 | 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
|
179 | 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
|
180 | 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
|
181 | 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
|
182 | 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
|
183 | 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
|
184 | 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
|
185 | 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
|
186 | 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
|
187 | 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
|
188 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
189 | CX_TEST_DO { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
190 | int64_t chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
191 | int ret; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
192 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
193 | 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
|
194 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
198 | 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
|
199 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
203 | 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
|
204 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
208 | 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
|
209 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
213 | 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
|
214 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
218 | 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
|
219 | CX_TEST_ASSERT(ret == -1); |
|
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, FALSE, &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 | } |
|
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
|
223 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | free(str4); |
|
77241b3ba544
add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
549
diff
changeset
|
228 | free(str5); |
|
77241b3ba544
add more test_io_http_stream_parse_chunk_header_invalid tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
549
diff
changeset
|
229 | 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
|
230 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | |
|
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 | // 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
|
239 | 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
|
240 | 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
|
241 | 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
|
242 | 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
|
243 | |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
245 | 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
|
246 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
247 | int64_t chunklen = -1; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
248 | 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
|
249 | CX_TEST_ASSERT(ret == 7); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
250 | CX_TEST_ASSERT(chunklen == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
251 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
252 | chunklen = -1; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
253 | 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
|
254 | CX_TEST_ASSERT(ret == 5); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
255 | CX_TEST_ASSERT(chunklen == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
256 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
257 | // expect 0 (incomplete) |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
258 | 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
|
259 | CX_TEST_ASSERT(ret == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
260 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
261 | 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
|
262 | 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
|
263 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
264 | } |
|
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 | 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
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | } |
|
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 | |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
272 | 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
|
273 | 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
|
274 | |
|
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 | 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
|
276 | 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
|
277 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
278 | 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
|
279 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
280 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
281 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
282 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
283 | 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
|
284 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
285 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
286 | CX_TEST_ASSERT(st->buf->size == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
287 | 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
|
288 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
289 | // 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
|
290 | char *msg2 = "test"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
291 | size_t msglen2 = strlen(msg2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
292 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
293 | w = net_write(http, msg2, msglen2); |
|
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 | CX_TEST_ASSERT(w == msglen2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
296 | 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
|
297 | 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
|
298 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
299 | } |
|
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 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | 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
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
304 | 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
|
305 | 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
|
306 | |
|
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 | 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
|
308 | 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
|
309 | 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
|
310 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
311 | 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
|
312 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
313 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
314 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
315 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
316 | 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
|
317 | size_t bufmsglen = strlen(bufmsg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
318 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
319 | 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
|
320 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
321 | 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
|
322 | cxstring s2 = cx_strn(bufmsg, bufmsglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
323 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
324 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
325 | CX_TEST_ASSERT(st->buf->size == bufmsglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
326 | CX_TEST_ASSERT(!cx_strcasecmp(s1, s2)); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
327 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
328 | // write again |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
329 | w = net_write(http, msg, msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
330 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
331 | 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
|
332 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
333 | 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
|
334 | 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
|
335 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
336 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
339 | 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
|
340 | 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
|
341 | |
|
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 | 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
|
343 | 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
|
344 | 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
|
345 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
346 | 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
|
347 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
348 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
349 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
350 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
351 | 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
|
352 | size_t bufmsglen = strlen(bufmsg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
353 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
354 | 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
|
355 | net_finish(http); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
356 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
357 | 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
|
358 | cxstring s2 = cx_strn(bufmsg, bufmsglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
359 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
360 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
361 | CX_TEST_ASSERT(st->buf->size == bufmsglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
362 | 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
|
363 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
364 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
367 | 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
|
368 | // 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
|
369 | // 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
|
370 | |
|
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 | 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
|
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 | 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
|
374 | 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
|
375 | 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
|
376 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
377 | 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
|
378 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
379 | // create test data |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
380 | CxBuffer *testdata = cxBufferCreate(NULL, 1024*1024*4, cxDefaultAllocator, 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
381 | 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
|
382 | cxBufferPut(testdata, 35+(i%91)); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
383 | } |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
384 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
385 | // 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
|
386 | // chunk size with each step |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
387 | size_t pos = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
388 | int j = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
389 | ssize_t i=15; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
390 | while(pos<testdata->size) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
391 | char *buf = testdata->space + pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
392 | size_t remaining = testdata->size - pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
393 | 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
|
394 | pos += len; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
395 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
396 | 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
|
397 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
398 | CX_TEST_ASSERT(w == len); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
399 | i+=100; // increase chunk size |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
400 | 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
|
401 | } |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
402 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
403 | // terminate chunk |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
404 | net_finish(http); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
405 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
406 | // 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
|
407 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
408 | // make sure the output is correctly encoded |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
409 | // 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
|
410 | // (which should be well-tested) |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
411 | WSBool first_chunk = TRUE; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
412 | int64_t chunklen = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
413 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
414 | char *buf = st->buf->space; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
415 | size_t bufsize = st->buf->size; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
416 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
417 | pos = 0; // st->buf position |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
418 | size_t srcpos = 0; // testdata position |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
419 | int debug_counter = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
420 | while(pos < bufsize) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
421 | ssize_t remaining = bufsize - pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
422 | ssize_t src_remaining = testdata->size - srcpos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
423 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
424 | 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
|
425 | first_chunk = FALSE; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
426 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
427 | // 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
|
428 | CX_TEST_ASSERT(ret > 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
429 | if(chunklen == 0) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
430 | CX_TEST_ASSERT(src_remaining == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
431 | break; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
432 | } |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
433 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
434 | CX_TEST_ASSERT(chunklen <= src_remaining); |
|
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 | char *src_chunk = testdata->space+srcpos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
437 | char *buf_chunk = buf+pos+ret; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
438 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
439 | 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
|
440 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
441 | pos += ret + chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
442 | srcpos += chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
443 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
444 | debug_counter++; |
|
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 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
447 | cxBufferFree(testdata); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
448 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
449 | testutil_iostream_destroy(st); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
450 | |
|
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
|
451 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | } |
|
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 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
454 | 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
|
455 | 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
|
456 | |
|
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 | 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
|
458 | 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
|
459 | 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
|
460 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
461 | 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
|
462 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | 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
|
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 | 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
|
466 | 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
|
467 | |
|
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 | 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
|
469 | 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
|
470 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | // 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
|
472 | 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
|
473 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
474 | CX_TEST_ASSERT(st->buf->size == 1); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
475 | 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
|
476 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | // 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
|
478 | w = net_write(http, msg, msglen); |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
479 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
480 | CX_TEST_ASSERT(st->buf->size == 2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
481 | 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
|
482 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | // 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
|
484 | w = net_write(http, msg, msglen); |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
485 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
486 | CX_TEST_ASSERT(st->buf->size == 3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
487 | 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
|
488 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | // 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
|
490 | w = net_write(http, msg, msglen); |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
491 | CX_TEST_ASSERT(w == 1); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
492 | CX_TEST_ASSERT(st->buf->size == 4); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
493 | 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
|
494 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495 | 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
|
496 | 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
|
497 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
498 | } |
|
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
|
499 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
501 | 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
|
502 | 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
|
503 | |
|
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 | 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
|
505 | 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
|
506 | 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
|
507 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
508 | 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
|
509 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
510 | 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
|
511 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
512 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
513 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
514 | size_t msglen_orig = msglen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
515 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
516 | // 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
|
517 | st->max_write = 3; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
518 | io_set_max_writes(1); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
519 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
520 | 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
|
521 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
522 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
523 | CX_TEST_ASSERT(st->buf->size == 3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
524 | 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
|
525 | 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
|
526 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
527 | w = net_write(http, msg, msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
528 | CX_TEST_ASSERT(w == 3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
529 | CX_TEST_ASSERT(st->buf->size == 6); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
530 | 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
|
531 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
532 | msg += w; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
533 | msglen -= w; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
534 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
535 | w = net_write(http, msg, msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
536 | CX_TEST_ASSERT(w == 3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
537 | CX_TEST_ASSERT(st->buf->size == 9); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
538 | 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
|
539 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
540 | st->max_write = 1024; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
541 | msg += w; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
542 | msglen -= w; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
543 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
544 | w = net_write(http, msg, msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
545 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
546 | 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
|
547 | 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
|
548 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
549 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
550 | 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
|
551 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
552 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
555 | 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
|
556 | 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
|
557 | |
|
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 | 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
|
559 | 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
|
560 | 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
|
561 | 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
|
562 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
563 | 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
|
564 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
565 | 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
|
566 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
567 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
568 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
569 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
570 | char *msg2 = "newmsg"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
571 | size_t msglen2 = strlen(msg2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
572 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
573 | char *msg3 = "msg3"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
574 | size_t msglen3 = strlen(msg3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
575 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
576 | 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
|
577 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
578 | 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
|
579 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
580 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
581 | 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
|
582 | 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
|
583 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
584 | 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
|
585 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
586 | w = net_write(http, msg2, msglen2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
587 | CX_TEST_ASSERT(w == msglen2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
588 | 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
|
589 | 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
|
590 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
591 | // 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
|
592 | st->max_write = 1; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
593 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
594 | w = net_write(http, "dummymsg", 8); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
595 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
596 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
597 | w = net_write(http, "dummymsg", 8); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
598 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
599 | 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
|
600 | 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
|
601 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
602 | st->max_write = 1024; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
603 | w = net_write(http, msg3, msglen3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
604 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
605 | CX_TEST_ASSERT(w == msglen3); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
606 | 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
|
607 | 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
|
608 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
609 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
610 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
611 | 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
|
612 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
613 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
616 | 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
|
617 | 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
|
618 | |
|
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 | 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
|
620 | 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
|
621 | 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
|
622 | 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
|
623 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
624 | 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
|
625 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
626 | 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
|
627 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
628 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
629 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
630 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
631 | char *msg2 = "newmsg"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
632 | size_t msglen2 = strlen(msg2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
633 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
634 | // 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
|
635 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
636 | st->max_write = 3 + msglen + 1; |
|
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 | 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
|
639 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
640 | CX_TEST_ASSERT(w == msglen); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
641 | 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
|
642 | 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
|
643 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
644 | 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
|
645 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
646 | w = net_write(http, msg2, msglen2); |
|
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 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
649 | 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
|
650 | 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
|
651 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
652 | // force partial header write again |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
653 | st->max_write = 1; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
654 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
655 | w = net_write(http, msg2, msglen2); |
|
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 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
658 | 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
|
659 | 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
|
660 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
661 | st->max_write = 1024; |
|
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 | w = net_write(http, msg2, msglen2); |
|
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 | CX_TEST_ASSERT(w ==msglen2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
666 | 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
|
667 | 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
|
668 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
669 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
670 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
671 | 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
|
672 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
673 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
676 | 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
|
677 | 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
|
678 | |
|
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 | 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
|
680 | 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
|
681 | 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
|
682 | 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
|
683 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
684 | 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
|
685 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
686 | 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
|
687 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
688 | // 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
|
689 | // 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
|
690 | // 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
|
691 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
692 | char *msg = "hello world!"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
693 | size_t msglen = strlen(msg); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
694 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
695 | char *msg2 = "newmsg"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
696 | size_t msglen2 = strlen(msg2); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
697 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
698 | char *msg_big = "hello world!newmsg"; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
699 | size_t msglen_big = strlen(msg_big); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
700 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
701 | st->max_write = 1; |
|
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 | 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
|
704 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
705 | CX_TEST_ASSERT(w == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
706 | CX_TEST_ASSERT(st->buf->size == 1); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
707 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
708 | st->max_write = 1024; |
|
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 | 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
|
711 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
712 | CX_TEST_ASSERT(w == msglen_big); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
713 | 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
|
714 | 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
|
715 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
716 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
717 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
718 | 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
|
719 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
720 | } |
|
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 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
723 | 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
|
724 | 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
|
725 | |
|
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 | 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
|
727 | 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
|
728 | 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
|
729 | 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
|
730 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
731 | 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
|
732 | |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
733 | // 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
|
734 | // 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
|
735 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
736 | // create test data |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
737 | CxBuffer *testdata = cxBufferCreate(NULL, 1024*16, cxDefaultAllocator, 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
738 | 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
|
739 | 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
|
740 | } |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
741 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
742 | st->max_write = 1; |
|
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 | size_t pos = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
745 | int chunksize = 1; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
746 | while(pos < testdata->size) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
747 | size_t available = testdata->size - pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
748 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
749 | char *chunk = testdata->space + pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
750 | size_t chunklen = chunksize > available ? available : chunksize; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
751 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
752 | // write chunk |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
753 | size_t chunkpos = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
754 | 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
|
755 | int writes = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
756 | while(chunkpos < chunklen) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
757 | 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
|
758 | CX_TEST_ASSERT(w >= 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
759 | chunkpos += w; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
760 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
761 | writes++; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
762 | CX_TEST_ASSERT(writes < max_writes); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
763 | } |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
764 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
765 | pos += chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
766 | chunksize += 5; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
767 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
768 | // increase max write size at some point |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
769 | if(pos + chunksize >= testdata->size) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
770 | st->max_write = INT_MAX; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
771 | } else if(pos > 1024*2) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
772 | if(pos < 1024*8) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
773 | st->max_write = 2; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
774 | } else { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
775 | st->max_write = 3; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
776 | } |
|
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
|
777 | } |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | } |
|
633
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
779 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
780 | // terminate chunk |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
781 | net_finish(http); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
782 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
783 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
784 | // 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
|
785 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
786 | // make sure the output is correctly encoded |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
787 | // 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
|
788 | // (which should be well-tested) |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
789 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
790 | WSBool first_chunk = TRUE; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
791 | int64_t chunklen = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
792 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
793 | char *buf = st->buf->space; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
794 | size_t bufsize = st->buf->size; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
795 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
796 | pos = 0; // st->buf position |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
797 | size_t srcpos = 0; // testdata position |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
798 | int debug_counter = 0; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
799 | while(pos < bufsize) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
800 | ssize_t remaining = bufsize - pos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
801 | ssize_t src_remaining = testdata->size - srcpos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
802 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
803 | 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
|
804 | first_chunk = FALSE; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
805 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
806 | // 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
|
807 | CX_TEST_ASSERT(ret > 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
808 | if(chunklen == 0) { |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
809 | CX_TEST_ASSERT(src_remaining == 0); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
810 | break; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
811 | } |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
812 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
813 | CX_TEST_ASSERT(chunklen <= src_remaining); |
|
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 | char *src_chunk = testdata->space+srcpos; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
816 | char *buf_chunk = buf+pos+ret; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
817 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
818 | 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
|
819 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
820 | pos += ret + chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
821 | srcpos += chunklen; |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
822 | |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
823 | debug_counter++; |
|
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 | |
|
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 | testutil_destroy_session(sn); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
828 | testutil_iostream_destroy(st); |
|
392ec9026b07
port old ucx2 tests to ucx3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
829 | 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
|
830 | |
|
0d80f8a2b29f
fix net_http_write when used with chunked transfer encoding and non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | } |
|
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 | } |