Remove CQL to Solr conversion and base on cql_transform_t
[yaz-moved-to-github.git] / src / http.c
index 223f7b5..54521b1 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -16,6 +16,7 @@
 #include <yaz/matchstr.h>
 #include <yaz/zgdu.h>
 #include <yaz/base64.h>
+#include <yaz/comstack.h>
 
 static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers,
                                   char **content_buf, int *content_len)
@@ -609,11 +610,13 @@ 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;
 
     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 +648,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