Content-Type charset fixes YAZ-701
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 7 Oct 2013 12:09:15 +0000 (14:09 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 7 Oct 2013 12:11:51 +0000 (14:11 +0200)
Do not inspect charset in Content-Type header for SOAP in decoding
of SRU. The paylaod (XML) itself tells what encoding it is.
In response, never supply encoding in Content-Type. The response
payload (XML) tells what it is (with no encoding in XML it's UTF-8).

src/seshigh.c
src/srwutil.c

index c744808..d594f43 100644 (file)
@@ -1933,11 +1933,6 @@ static void process_http_request(association *assoc, request *req)
             hres->code = http_code;
 
             strcpy(ctype, "text/xml");
             hres->code = http_code;
 
             strcpy(ctype, "text/xml");
-            if (charset && strlen(charset) < sizeof(ctype)-30)
-            {
-                strcat(ctype, "; charset=");
-                strcat(ctype, charset);
-            }
             z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
         }
         else
             z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
         }
         else
index fdf9944..5a4f576 100644 (file)
@@ -234,12 +234,19 @@ static void grab_charset(ODR o, const char *content_type, char **charset)
         const char *charset_p = 0;
         if (content_type && (charset_p = strstr(content_type, "; charset=")))
         {
         const char *charset_p = 0;
         if (content_type && (charset_p = strstr(content_type, "; charset=")))
         {
-            int i = 0;
-            charset_p += 10;
-            while (i < 20 && charset_p[i] &&
-                   !strchr("; \n\r", charset_p[i]))
-                i++;
-            *charset = odr_strdupn(o, charset_p, i);
+            int j = 0, i = 0;
+            int sep = 0;
+            charset_p += 10; /* skip ; charset=  */
+            if (charset_p[i] == '"' || charset_p[i] == '\'')
+                sep = charset_p[i++];
+            *charset = odr_strdup(o, charset_p);
+            while (charset_p[i] && charset_p[i] != sep)
+            {
+                if (charset_p[i] == '\\' && charset_p[i+1])
+                    i++;
+                (*charset)[j++] = charset_p[i++];
+            }
+            (*charset)[j] = '\0';
         }
     }
 }
         }
     }
 }
@@ -277,7 +284,6 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                 p1 = p0 + strlen(p0);
             if (p1 != p0)
                 db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0);
                 p1 = p0 + strlen(p0);
             if (p1 != p0)
                 db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0);
-            grab_charset(decode, content_type, charset);
 
             ret = z_soap_codec(decode, soap_package,
                                &hreq->content_buf, &hreq->content_len,
 
             ret = z_soap_codec(decode, soap_package,
                                &hreq->content_buf, &hreq->content_len,
@@ -1104,7 +1110,7 @@ int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
                                  srw_pdu->username, srw_pdu->password);
     z_HTTP_header_add_content_type(odr,
                                    &hreq->headers,
                                  srw_pdu->username, srw_pdu->password);
     z_HTTP_header_add_content_type(odr,
                                    &hreq->headers,
-                                   "text/xml", charset);
+                                   "text/xml", 0 /* no charset in MIME */);
 
     z_HTTP_header_add(odr, &hreq->headers,
                       "SOAPAction", "\"\"");
 
     z_HTTP_header_add(odr, &hreq->headers,
                       "SOAPAction", "\"\"");