| 250 CX_TEST_DO { |
250 CX_TEST_DO { |
| 251 cxstring response_str = cx_str( |
251 cxstring response_str = cx_str( |
| 252 "HTTP/1.1 200 OK\r\n" |
252 "HTTP/1.1 200 OK\r\n" |
| 253 "Content-length: 21\r\n" |
253 "Content-length: 21\r\n" |
| 254 "\r\n" |
254 "\r\n" |
| 255 "Hello World!---post1\n"); |
255 "Hello World!---post2\n"); |
| 256 cxstring *response = calloc(response_str.length, sizeof(cxstring)); |
256 cxstring *response = calloc(response_str.length, sizeof(cxstring)); |
| 257 for(int i=0;i<response_str.length;i++) { |
257 for(int i=0;i<response_str.length;i++) { |
| 258 response[i] = cx_strn(response_str.ptr+i, 1); |
258 response[i] = cx_strn(response_str.ptr+i, 1); |
| 259 } |
259 } |
| 260 |
260 |
| 261 cxstring request_body = cx_str("test request body, needs more than one read (len > 16)\n"); |
261 cxstring request_body = cx_str("test request body, needs more than one read (len > 16)\n"); |
| 262 |
262 |
| 263 CxBuffer *out = cxBufferCreate(NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
263 CxBuffer *out = cxBufferCreate(NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
| 264 |
264 |
| 265 CX_TEST_CALL_SUBROUTINE(test_httpclient, request_body, TRUE, response, response_str.length, out); |
265 CX_TEST_CALL_SUBROUTINE(test_httpclient, request_body, TRUE, response, response_str.length, out); |
| 266 CX_TEST_ASSERT(!cx_strcmp(cx_strn(out->space, out->size), "Hello World!---post1\n")); |
266 CX_TEST_ASSERT(!cx_strcmp(cx_strn(out->space, out->size), "Hello World!---post2\n")); |
| 267 |
267 |
| 268 cxBufferFree(out); |
268 cxBufferFree(out); |
| 269 } |
269 } |
| 270 } |
270 } |
| |
271 |
| |
272 CX_TEST(test_http_client_post_ctlen_large) { |
| |
273 CX_TEST_DO { |
| |
274 cxstring response = cx_str( |
| |
275 "HTTP/1.1 200 OK\r\n" |
| |
276 "Content-length: 21\r\n" |
| |
277 "\r\n" |
| |
278 "Hello World!---post3\n"); |
| |
279 |
| |
280 size_t ctlen = 1024*64; |
| |
281 char *req_body = malloc(ctlen); |
| |
282 cxstring request_body = cx_strn(req_body, ctlen); |
| |
283 |
| |
284 CxBuffer *out = cxBufferCreate(NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); |
| |
285 |
| |
286 request_body_max_read = 4096; |
| |
287 CX_TEST_CALL_SUBROUTINE(test_httpclient, request_body, FALSE, &response, 1, out); |
| |
288 CX_TEST_ASSERT(!cx_strcmp(cx_strn(out->space, out->size), "Hello World!---post3\n")); |
| |
289 |
| |
290 cxBufferFree(out); |
| |
291 free(req_body); |
| |
292 } |
| |
293 } |