diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-11-01 23:41:53 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-11-02 20:57:08 -0700 |
| commit | db92342b43d429b8b07244cc003a8589a1b1c542 (patch) | |
| tree | 5624a3142b8309257ff523b0bf85343bee08033d /tests/httpclient.c | |
| parent | 156604bd07ee60faa323968c71627f1c701b473a (diff) | |
| download | nng-db92342b43d429b8b07244cc003a8589a1b1c542.tar.gz nng-db92342b43d429b8b07244cc003a8589a1b1c542.tar.bz2 nng-db92342b43d429b8b07244cc003a8589a1b1c542.zip | |
fixes #682 Support for Chunked Transfer Coding
This is the client side only, although the work is structured to
support server applications. The chunked API is for now private,
although the intent to is to make it public for applications who
really want to use it.
Note that chunked transfer encoding puts data through extra copies.
First it copies through the buffering area (because I have to be able
to extract variable length strings from inside the data stream), and then
again to reassemble the chunks into a single unified object.
We do assume that the user wants the entire thing as a single object.
This means that using this to pull unbounded data will just silently
consume all memory. Use caution!
Diffstat (limited to 'tests/httpclient.c')
| -rw-r--r-- | tests/httpclient.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/httpclient.c b/tests/httpclient.c index 6964bcc2..75ecbae9 100644 --- a/tests/httpclient.c +++ b/tests/httpclient.c @@ -26,6 +26,10 @@ const uint8_t example_sum[20] = { 0x0e, 0x97, 0x3b, 0x59, 0xf4, 0x76, 0x00, 0x7f, 0xd1, 0x0f, 0x87, 0xf3, 0x47, 0xc3, 0x95, 0x60, 0x65, 0x51, 0x6f, 0xc0 }; +const uint8_t chunked_sum[20] = { 0x9b, 0x06, 0xfb, 0xee, 0x51, 0xc6, 0x42, + 0x69, 0x1c, 0xb3, 0xaa, 0x38, 0xce, 0xb8, 0x0b, 0x3a, 0xc8, 0x3b, 0x96, + 0x68 }; + TestMain("HTTP Client", { atexit(nng_fini); @@ -208,4 +212,49 @@ TestMain("HTTP Client", { So(memcmp(digest, example_sum, 20) == 0); }); }); + + Convey("Given a client (chunked)", { + nng_aio * aio; + nng_http_client *cli; + nng_url * url; + + So(nng_aio_alloc(&aio, NULL, NULL) == 0); + + So(nng_url_parse(&url, + "http://anglesharp.azurewebsites.net/Chunked") == 0); + // "https://jigsaw.w3.org/HTTP/ChunkedScript") + //== 0); + + So(nng_http_client_alloc(&cli, url) == 0); + nng_aio_set_timeout(aio, 10000); // 10 sec timeout + + Reset({ + nng_http_client_free(cli); + nng_url_free(url); + nng_aio_free(aio); + }); + + Convey("One off exchange works", { + nng_http_req *req; + nng_http_res *res; + void * data; + size_t len; + uint8_t digest[20]; + + So(nng_http_req_alloc(&req, url) == 0); + So(nng_http_res_alloc(&res) == 0); + Reset({ + nng_http_req_free(req); + nng_http_res_free(res); + }); + + nng_http_client_transact(cli, req, res, aio); + nng_aio_wait(aio); + So(nng_aio_result(aio) == 0); + So(nng_http_res_get_status(res) == 200); + nng_http_res_get_data(res, &data, &len); + nni_sha1(data, len, digest); + So(memcmp(digest, chunked_sum, 20) == 0); + }); + }); }) |
