diff options
author | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2004-12-30 11:55:13 +0000 |
---|---|---|
committer | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2004-12-30 11:55:13 +0000 |
commit | 4bbd032fc525b0185c4bfe3f73395ab857e507e8 (patch) | |
tree | 9b0191b7f4e0b47888322184f0f9e4608d400ee2 /src/ne_redirect.c | |
parent | 5313dc13b9ed83dc429edc0fcec68980254ac91b (diff) | |
download | neon-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_redirect.c')
-rw-r--r-- | src/ne_redirect.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/ne_redirect.c b/src/ne_redirect.c index 1985793..3d751e6 100644 --- a/src/ne_redirect.c +++ b/src/ne_redirect.c @@ -39,7 +39,6 @@ #define REDIRECT_ID "http://www.webdav.org/neon/hooks/http-redirect" struct redirect { - char *location; char *requri; int valid; /* non-zero if .uri contains a redirect */ ne_uri uri; @@ -50,11 +49,8 @@ static void create(ne_request *req, void *session, const char *method, const char *uri) { struct redirect *red = session; - NE_FREE(red->location); NE_FREE(red->requri); red->requri = ne_strdup(uri); - ne_add_response_header_handler(req, "Location", ne_duplicate_header, - &red->location); } #define REDIR(n) ((n) == 301 || (n) == 302 || (n) == 303 || \ @@ -63,14 +59,17 @@ create(ne_request *req, void *session, const char *method, const char *uri) static int post_send(ne_request *req, void *private, const ne_status *status) { struct redirect *red = private; + const char *location = ne_get_response_header(req, "Location"); + ne_buffer *path = NULL; + int ret; /* Don't do anything for non-redirect status or no Location header. */ - if (!REDIR(status->code) || red->location == NULL) + if (!REDIR(status->code) || location == NULL) return NE_OK; - if (strstr(red->location, "://") == NULL && red->location[0] != '/') { + if (strstr(location, "://") == NULL && location[0] != '/') { /* FIXME: remove this relative URI resolution hack. */ - ne_buffer *path = ne_buffer_create(); + path = ne_buffer_create(); char *pnt; ne_buffer_zappend(path, red->requri); @@ -81,36 +80,37 @@ static int post_send(ne_request *req, void *private, const ne_status *status) *(pnt+1) = '\0'; ne_buffer_altered(path); } - ne_buffer_zappend(path, red->location); - ne_free(red->location); - red->location = ne_buffer_finish(path); + ne_buffer_zappend(path, location); + location = path->data; } /* free last uri. */ ne_uri_free(&red->uri); /* Parse the Location header */ - if (ne_uri_parse(red->location, &red->uri) || red->uri.path == NULL) { + if (ne_uri_parse(location, &red->uri) || red->uri.path == NULL) { red->valid = 0; ne_set_error(red->sess, _("Could not parse redirect location.")); - return NE_ERROR; + ret = NE_ERROR; + } else { + /* got a valid redirect. */ + red->valid = 1; + ret = NE_REDIRECT; + + if (!red->uri.host) { + /* Not an absoluteURI: breaks 2616 but everybody does it. */ + ne_fill_server_uri(red->sess, &red->uri); + } } - /* got a valid redirect. */ - red->valid = 1; - - if (!red->uri.host) { - /* Not an absoluteURI: breaks 2616 but everybody does it. */ - ne_fill_server_uri(red->sess, &red->uri); - } + if (path) ne_buffer_destroy(path); - return NE_REDIRECT; + return ret; } static void free_redirect(void *cookie) { struct redirect *red = cookie; - NE_FREE(red->location); ne_uri_free(&red->uri); if (red->requri) ne_free(red->requri); |