X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp.c;h=c05dc02109bfb3e682135f8593f742e62ae1a4d4;hb=896b145fa7a02199bfc3e8aa824c018b9d7cbf98;hp=3f8fb53176cc4aadab5630ef0c10e996926d0c42;hpb=4f3bcae93d51a26709c12b51261c3d95af610cb2;p=yaz-moved-to-github.git diff --git a/src/http.c b/src/http.c index 3f8fb53..c05dc02 100644 --- a/src/http.c +++ b/src/http.c @@ -317,6 +317,48 @@ Z_GDU *z_get_HTTP_Request_host_path(ODR odr, return p; } +Z_GDU *z_get_HTTP_Request_uri(ODR odr, const char *uri, const char *args, + int use_full_uri) +{ + Z_GDU *p = z_get_HTTP_Request(odr); + const char *cp0 = strstr(uri, "://"); + const char *cp1 = 0; + if (cp0) + cp0 = cp0+3; + else + cp0 = uri; + + cp1 = strchr(cp0, '/'); + if (!cp1) + cp1 = cp0+strlen(cp0); + + if (cp0 && cp1) + { + char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1); + memcpy (h, cp0, cp1 - cp0); + h[cp1-cp0] = '\0'; + z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, + "Host", h); + } + + if (!args) + { + if (*cp1) + args = cp1 + 1; + else + args = ""; + } + p->u.HTTP_Request->path = odr_malloc(odr, cp1 - uri + strlen(args) + 2); + if (use_full_uri) + { + memcpy(p->u.HTTP_Request->path, uri, cp1 - uri); + strcpy(p->u.HTTP_Request->path + (cp1 - uri), "/"); + } + else + strcpy(p->u.HTTP_Request->path, "/"); + strcat(p->u.HTTP_Request->path, args); + return p; +} Z_GDU *z_get_HTTP_Response(ODR o, int code) {