X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fhttp.c;h=0fdd465907b00d565edcaa346e60d87a8d06b3f7;hp=d79fd10050108d36132cf9ed81042e69b7866e15;hb=c9c54c9f75cfea59f26489d1b0ef011dafa4297e;hpb=473824797f568578dc17d7242551cb2f7ccef46c diff --git a/src/http.c b/src/http.c index d79fd10..0fdd465 100644 --- a/src/http.c +++ b/src/http.c @@ -16,6 +16,7 @@ #include #include #include +#include static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, char **content_buf, int *content_len) @@ -510,6 +511,12 @@ int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p) int lspace = 0; *hr_p = hr; + hr->method = 0; + hr->version = 0; + hr->path = 0; + hr->headers = 0; + hr->content_buf = 0; + hr->content_len = 0; /* method .. */ for (i = 0; buf[i] != ' '; i++) if (i >= size-5 || i > 30) @@ -609,11 +616,15 @@ int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr) int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr) { Z_HTTP_Header *h; + char *cp; int top0 = o->op->top; + if (!hr->method || !hr->path) + return 0; odr_write(o, hr->method, strlen(hr->method)); odr_write(o, " ", 1); - odr_write(o, hr->path, strlen(hr->path)); + cp = strchr(hr->path, '#'); + odr_write(o, hr->path, cp ? (cp - hr->path) : strlen(hr->path)); odr_write(o, " HTTP/", 6); odr_write(o, hr->version, strlen(hr->version)); odr_write(o, "\r\n", 2); @@ -645,6 +656,32 @@ int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr) return 1; } +const char *yaz_check_location(ODR odr, const char *uri, const char *location, + int *host_change) +{ + if (*location == '/') + { /* relative location */ + char *args = 0; + char *nlocation = (char *) odr_malloc(odr, strlen(location) + + strlen(uri) + 3); + strcpy(nlocation, uri); + cs_get_host_args(nlocation, (const char **) &args); + if (!args || !*args) + args = nlocation + strlen(nlocation); + else + args--; + strcpy(args, location); + *host_change = 0; + return nlocation; + } + else + { + /* we don't check if host is the same as before - yet */ + *host_change = 1; + return location; + } +} + /* * Local variables: * c-basic-offset: 4