diff options
author | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2005-06-21 06:32:52 +0000 |
---|---|---|
committer | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2005-06-21 06:32:52 +0000 |
commit | eeab34f875b1ef81a583c45775b85e300f66fff5 (patch) | |
tree | bfb670817addb05ee85384a391af53aa23fa04bf | |
parent | 6d63f8980cb6ea9922aa05dfeed0855331e6148f (diff) | |
download | neon-eeab34f875b1ef81a583c45775b85e300f66fff5.tar.gz |
* src/ne_compress.c (process_footer): Don't invoke reader callback
with len=0 here as well when end-of-response is really reached.
(do_inflate): Do pass on the reader callback return value.
* test/compress.c (reader): Catch multiple invocations with len=0.
(retry_accept): Reset the reader state.
(reader_abort, compress_abort): New functions.
git-svn-id: http://svn.webdav.org/repos/projects/neon/branches/0.25.x@627 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
-rw-r--r-- | src/ne_compress.c | 6 | ||||
-rw-r--r-- | test/compress.c | 56 |
2 files changed, 59 insertions, 3 deletions
diff --git a/src/ne_compress.c b/src/ne_compress.c index a8926f8..bd614ff 100644 --- a/src/ne_compress.c +++ b/src/ne_compress.c @@ -154,8 +154,6 @@ static int process_footer(ne_decompress *ctx, uLong crc = BUF2UINT(ctx->footer) & 0xFFFFFFFF; if (crc == ctx->checksum) { ctx->state = NE_Z_FINISHED; - /* reader requires a size=0 call at end-of-response */ - ctx->reader(ctx->userdata, NULL, 0); NE_DEBUG(NE_DBG_HTTP, "compress: End of response; checksum match.\n"); } else { NE_DEBUG(NE_DBG_HTTP, "compress: End of response; checksum mismatch: " @@ -220,7 +218,9 @@ static int do_inflate(ne_decompress *ctx, const char *buf, size_t len) /* pass on the inflated data, if any */ if (ctx->zstr.total_out > 0) { - ctx->reader(ctx->userdata, ctx->outbuf, ctx->zstr.total_out); + int rret = ctx->reader(ctx->userdata, ctx->outbuf, + ctx->zstr.total_out); + if (rret) return rret; } } while (ret == Z_OK && ctx->zstr.avail_in > 0); diff --git a/test/compress.c b/test/compress.c index d6d78cf..8eadf23 100644 --- a/test/compress.c +++ b/test/compress.c @@ -58,6 +58,14 @@ static int reader(void *ud, const char *block, size_t len) if (failed == f_mismatch) return -1; + /* catch multiple len == 0 call as issued by 0.25.0 only: */ + if (failed == f_complete) { + NE_DEBUG(NE_DBG_HTTP, "reader: called after complete, len=%d\n", + (int)len); + failed = f_mismatch; + return -1; + } + if (failed == f_partial && len == 0) { if (b->len != 0) { NE_DEBUG(NE_DBG_HTTP, "reader: got length %d at EOF\n", @@ -357,6 +365,7 @@ static int retry_accept(void *ud, ne_request *req, const ne_status *st) } expect->len = 5; + failed = f_partial; /* reset the state */ return 1; } @@ -369,6 +378,52 @@ static int retry_compress(void) return retry_compress_helper(retry_accept, &resp, &expect); } +#define READER_ABORT_ERR "reader_abort error string" + +static int reader_abort(void *ud, const char *buf, size_t len) +{ + ne_session *sess = ud; + ne_set_error(sess, READER_ABORT_ERR); + return len; +} + +/* check that a callback abort does abort the response */ +static int compress_abort(void) +{ + ne_session *sess; + ne_request *req; + struct serve_file_args sfargs; + ne_decompress *dc; + int ret; + + sfargs.fname = "file1.gz"; + sfargs.headers = "Content-Encoding: gzip\r\n"; + sfargs.chunks = 0; + + CALL(make_session(&sess, serve_file, &sfargs)); + + req = ne_request_create(sess, "GET", "/abort"); + + dc = ne_decompress_reader(req, ne_accept_2xx, reader_abort, sess); + + ret = ne_request_dispatch(req); + + reap_server(); + + ONN("request was not aborted", ret != NE_ERROR); + ONV(strcmp(ne_get_error(sess), READER_ABORT_ERR), + ("session error was %s not %s", + ne_get_error(sess), READER_ABORT_ERR)); + + reap_server(); + ne_decompress_destroy(dc); + ne_request_destroy(req); + ne_session_destroy(sess); + + return OK; + +} + ne_test tests[] = { T_LEAKY(init), T(not_compressed), @@ -390,5 +445,6 @@ ne_test tests[] = { T(chunked_10b_wn), T(retry_notcompress), T(retry_compress), + T(compress_abort), T(NULL) }; |