summaryrefslogtreecommitdiff
path: root/src/ne_compress.c
diff options
context:
space:
mode:
authorjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2004-12-30 11:55:13 +0000
committerjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2004-12-30 11:55:13 +0000
commit4bbd032fc525b0185c4bfe3f73395ab857e507e8 (patch)
tree9b0191b7f4e0b47888322184f0f9e4608d400ee2 /src/ne_compress.c
parent5313dc13b9ed83dc429edc0fcec68980254ac91b (diff)
downloadneon-4bbd032fc525b0185c4bfe3f73395ab857e507e8.tar.gz
Remove callback-based response header handling in favour of
ne_get_response_header interface: * src/ne_request.h (ne_get_response_header): New function, replacing ne_add_response_header_handler and ne_add_response_header_catcher. * src/ne_request.c (struct header_handler): Remove. (struct field): Add. (struct ne_request_s): Store a hash of header fields rather than a hash of callbacks. (te_hdr_handler, connection_hdr_handler, clength_hdr_handler, ne_add_response_header_catcher, ne_add_response_header_handler, ne_duplicate_header, ne_handle_numeric_header): Remove functions. (get_response_header_hv, ne_get_response_header, add_response_header, remove_response_header): New functions. (ne_request_create): Don't register the callbacks. (read_response_headers): Call add_response_header for each field. (ne_begin_request): Move handling of Connection, T-E and C-L headers here. Comply with 2616/14.10 w.r.t. Connection header handling in HTTP/1.0 responses. (ne_request_dispatch): Use ne_discard_response (unrelated). * src/ne_redirect.c (struct redirect): Remove location field. (post_send): Adjust to retrieve location header here. * src/ne_basic.h (ne_get_content_type): Replaces ne_content_type_handler. * src/ne_basic.c (dispatch_to_fd): New function. (get_to_fd, get_lastmodified, clength_hdr_handler, accept_206, content_range_hdr_handler): Remove functions. (ne_getmodtime): Adjust to use ne_get_response_header. (ne_get_range, ne_get, ne_post): Adjust to use dispatch_to_fd. (ne_get_content_type): Adjust for new API, use ne_get_response_header. (parse_dav_header, ne_options): Adjust to use ne_get_response_header. * src/ne_compress.c (struct ne_decompress_s): Add ne_request * field, remove enchdr field. (gz_reader): Retrieve C-E header on demand, here. (ne_decompress_reader, ne_decompress_destroy): Remove C-E response header duplication. * src/ne_auth.c (auth_request): Remove auth_hdr, auth_info_hdr fields. (ah_collect_header): Remove function. (ah_create, ah_destroy): Remove response-header callback handling. (ah_post_send): Retrieve -Authenticate header here; correctly handle the broken proxy which sends a 401 in response to CONNECT. * src/ne_locks.c (lk_startelm): Retrieve Lock-Token header here. (get_ltoken_hdr): Remove function. (ne_lock, ne_lock_refresh): Remove response-header handling. * test/basic.c (content_type): Test new interface. * test/request.c (expect_header_value): Adjust to accept NULL value, use ne_get_response_header interface. (multi_header): Test new ne_get_response_header multi-header handling. (multi_header2, strip_http10_connhdr, strip_http10_connhdr2): New tests. git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@367 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
Diffstat (limited to 'src/ne_compress.c')
-rw-r--r--src/ne_compress.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/ne_compress.c b/src/ne_compress.c
index c6f2e48..b36d384 100644
--- a/src/ne_compress.c
+++ b/src/ne_compress.c
@@ -44,12 +44,12 @@
* be inflated. */
struct ne_decompress_s {
+ ne_request *request; /* associated request. */
ne_session *session; /* associated session. */
/* temporary buffer for holding inflated data. */
char outbuf[BUFSIZ];
z_stream zstr;
int zstrinit; /* non-zero if zstr has been initialized */
- char *enchdr; /* value of Content-Enconding response header. */
/* pass blocks back to this. */
ne_block_reader reader;
@@ -241,13 +241,15 @@ static int gz_reader(void *ud, const char *buf, size_t len)
ne_decompress *ctx = ud;
const char *zbuf;
size_t count;
+ const char *hdr;
if (len == 0) {
/* End of response: */
switch (ctx->state) {
- case NE_Z_BEFORE_DATA:
- if (ctx->enchdr && strcasecmp(ctx->enchdr, "gzip") == 0) {
- /* response was truncated: break out. */
+ case NE_Z_BEFORE_DATA:
+ hdr = ne_get_response_header(ctx->request, "Content-Encoding");
+ if (hdr && strcasecmp(hdr, "gzip") == 0) {
+ /* response was truncated: return error. */
break;
}
/* else, fall through */
@@ -280,7 +282,8 @@ static int gz_reader(void *ud, const char *buf, size_t len)
case NE_Z_BEFORE_DATA:
/* work out whether this is a compressed response or not. */
- if (ctx->enchdr && strcasecmp(ctx->enchdr, "gzip") == 0) {
+ hdr = ne_get_response_header(ctx->request, "Content-Encoding");
+ if (hdr && strcasecmp(hdr, "gzip") == 0) {
int ret;
NE_DEBUG(NE_DBG_HTTP, "compress: got gzipped stream.\n");
@@ -376,9 +379,6 @@ void ne_decompress_destroy(ne_decompress *ctx)
* return value. */
inflateEnd(&ctx->zstr);
- if (ctx->enchdr)
- ne_free(ctx->enchdr);
-
ne_free(ctx);
}
@@ -396,15 +396,13 @@ ne_decompress *ne_decompress_reader(ne_request *req, ne_accept_response acpt,
ne_add_request_header(req, "Accept-Encoding", "gzip");
- ne_add_response_header_handler(req, "Content-Encoding",
- ne_duplicate_header, &ctx->enchdr);
-
ne_add_response_body_reader(req, gz_acceptor, gz_reader, ctx);
ctx->state = NE_Z_BEFORE_DATA;
ctx->reader = rdr;
ctx->userdata = userdata;
ctx->session = ne_get_session(req);
+ ctx->request = req;
/* initialize the checksum. */
ctx->checksum = crc32(0L, Z_NULL, 0);
ctx->acceptor = acpt;