| 736 } |
736 } |
| 737 |
737 |
| 738 // because we are using chunked transfer encoding, the result buffer |
738 // because we are using chunked transfer encoding, the result buffer |
| 739 // (buf) should contain more than 128 bytes (additional chunk headers) |
739 // (buf) should contain more than 128 bytes (additional chunk headers) |
| 740 CX_TEST_ASSERT(buf.pos > 128); |
740 CX_TEST_ASSERT(buf.pos > 128); |
| 741 // check for chunk headers |
|
| 742 // TODO |
|
| 743 //CX_TEST_ASSERT(!cx_strcmp(cx_strn(buf.space, 4), "10\r\n")); |
|
| 744 |
|
| 745 size_t offset = buf.pos; |
|
| 746 |
741 |
| 747 // change chunk size to 128 |
742 // change chunk size to 128 |
| 748 req.max_reads = 9999; |
743 req.max_reads = 9999; |
| 749 req.chunksize = 128; |
744 req.chunksize = 128; |
| 750 while(req.cur_reads <= req.max_reads) { |
745 while(req.cur_reads <= req.max_reads) { |
| 760 } |
755 } |
| 761 } |
756 } |
| 762 CX_TEST_ASSERT(req.cur_reads < req.max_reads); |
757 CX_TEST_ASSERT(req.cur_reads < req.max_reads); |
| 763 //CX_TEST_ASSERT(buf.size == 1084 + 5); |
758 //CX_TEST_ASSERT(buf.size == 1084 + 5); |
| 764 |
759 |
| 765 // TODO |
760 // verify chunks |
| 766 /* |
761 char test_request_body[1024]; |
| 767 // check chunks |
762 memset(test_request_body, 0, 1024); |
| 768 char testbuf[128]; |
763 |
| 769 memset(testbuf, 'x', 128); |
764 int pos = 0; |
| 770 cxstring x1 = cx_strn(buf.space + 296, 128); |
765 int chunklen = 0; |
| 771 CX_TEST_ASSERT(!cx_strcmp(x1, cx_strn(testbuf, 128))); |
766 char *str = buf.space; |
| 772 cxstring x2 = cx_strn(buf.space + 560, 128); |
767 while(str < buf.space + buf.size) { |
| 773 CX_TEST_ASSERT(!cx_strcmp(x2, cx_strn(testbuf, 128))); |
768 cxstring chunkheader = cx_strn(str, 2); |
| 774 cxstring x3 = cx_strn(buf.space + 824, 128); |
769 if(!cx_strcmp(chunkheader, "0\r")) { |
| 775 CX_TEST_ASSERT(!cx_strcmp(x3, cx_strn(testbuf, 128))); |
770 chunkheader.length = 1; |
| 776 memset(testbuf, 'y', 128); |
771 } |
| 777 cxstring y1 = cx_strn(buf.space + 164, 128); |
772 int ret = cx_strtoi(chunkheader, &chunklen, 16); |
| 778 CX_TEST_ASSERT(!cx_strcmp(y1, cx_strn(testbuf, 128))); |
773 CX_TEST_ASSERT(ret == 0); |
| 779 cxstring z1 = cx_strn(buf.space + 428, 128); |
774 if(chunklen == 0) { |
| 780 memset(testbuf, 'z', 128); |
775 break; |
| 781 CX_TEST_ASSERT(!cx_strcmp(z1, cx_strn(testbuf, 128))); |
776 } |
| 782 */ |
777 |
| |
778 char *data = str + 4; |
| |
779 memcpy(test_request_body + pos, data, chunklen); |
| |
780 pos += chunklen; |
| |
781 str = data + chunklen; |
| |
782 } |
| |
783 CX_TEST_ASSERT(!memcmp(request_body, test_request_body, 1024)); |
| 783 |
784 |
| 784 // cleanup |
785 // cleanup |
| 785 close(fds[0]); |
786 close(fds[0]); |
| 786 close(fds[1]); |
787 close(fds[1]); |
| 787 http_client_free(client); |
788 http_client_free(client); |