SRW/SRU update: use uri instead of code for diagnostic
[yaz-moved-to-github.git] / src / zgdu.c
index a37a96e..543eda6 100644 (file)
@@ -2,11 +2,12 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: zgdu.c,v 1.1 2003-10-27 12:21:36 adam Exp $
+ * $Id: zgdu.c,v 1.5 2003-12-31 00:14:01 adam Exp $
  */
 
 #include <yaz/odr.h>
 #include <yaz/yaz-version.h>
+#include <yaz/yaz-iconv.h>
 #include <yaz/zgdu.h>
 
 static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers,
@@ -96,7 +97,7 @@ void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n,
 const char *z_HTTP_header_lookup(Z_HTTP_Header *hp, const char *n)
 {
     for (; hp; hp = hp->next)
-        if (!strcmp(hp->name, n))
+        if (!yaz_matchstr(hp->name, n))
             return hp->value;
     return 0;
 }
@@ -293,11 +294,10 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
             if (!z_HTTP_header_lookup((*p)->u.HTTP_Response->headers,
                                       "Content-Length"))
             {
-                char lstr[20];
-                sprintf(lstr, "%d", (*p)->u.HTTP_Response->content_len);
-                z_HTTP_header_add(o,
-                                  &(*p)->u.HTTP_Response->headers,
-                                  "Content-Length", lstr);
+                char lstr[60];
+                sprintf(lstr, "Content-Length: %d\r\n",
+                       (*p)->u.HTTP_Response->content_len);
+                odr_write(o, (unsigned char *) lstr, strlen(lstr));
             }
             for (h = (*p)->u.HTTP_Response->headers; h; h = h->next)
             {
@@ -332,11 +332,10 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
                 !z_HTTP_header_lookup((*p)->u.HTTP_Request->headers,
                                       "Content-Length"))
             {
-                char lstr[20];
-                sprintf(lstr, "%d", (*p)->u.HTTP_Request->content_len);
-                z_HTTP_header_add(o,
-                                  &(*p)->u.HTTP_Request->headers,
-                                  "Content-Length", lstr);
+                char lstr[60];
+                sprintf(lstr, "Content-Length: %d\r\n",
+                       (*p)->u.HTTP_Request->content_len);
+                odr_write(o, (unsigned char *) lstr, strlen(lstr));
             }
             for (h = (*p)->u.HTTP_Request->headers; h; h = h->next)
             {
@@ -352,7 +351,9 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
                           (*p)->u.HTTP_Request->content_len);
             if (o->direction == ODR_PRINT)
             {
-                fprintf(o->print, "-- HTTP request:\n%.*s\n", o->top, o->buf);
+                fprintf(o->print, "-- HTTP request:\n%.*s\n", o->top - top0,
+                        o->buf + top0);
+                fprintf(o->print, "-- \n");
             }
             break;
         case Z_GDU_Z3950: