[Kazehakase-devel 1941] kz-http.c: Field names are case-insensitive.

Back to archive index

Kazuhiro NISHIYAMA zn****@mbf*****
2005年 2月 23日 (水) 17:49:16 JST


西山和広です。

http headerのField namesのところはcase-insensitiveなので
そうなるようにしてみました。
「:」の後の空白が複数ある場合にも対応してみました。


「Content-Encoding: gzip」に対応させたかったのですが、
ダウンロードが終わった後に、gunzipを通せばいいかと
思ったら、ダウンロードしてきたデータはKzHTTPでは溜めずに
KzIOに渡してしまっていて、ちょっと修正するだけでは
無理そうだったのであきらめてしまいました。


-- 
|ZnZ(ゼット エヌ ゼット)
|西山和広(Kazuhiro NISHIYAMA)
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /cvsroot/kazehakase/kazehakase/ChangeLog,v
retrieving revision 1.1308
diff -u -p -r1.1308 ChangeLog
--- ChangeLog	20 Feb 2005 13:08:25 -0000	1.1308
+++ ChangeLog	23 Feb 2005 06:17:25 -0000
@@ -20,6 +20,11 @@
 	Do not popup thumbnail when the link indicates image file.
 	Thanks to atzm san.
 
+2005-02-18  Kazuhiro NISHIYAMA <zn****@mbf*****>
+
+	* src/net/kz-http.c:
+	Field names are case-insensitive. (RFC 2616 4.2)
+
 2005-02-15  Hiroyuki Ikezoe <poinc****@ikezo*****>
 
 	* src/kz-window.c:
Index: src/net/kz-http.c
===================================================================
RCS file: /cvsroot/kazehakase/kazehakase/src/net/kz-http.c,v
retrieving revision 1.52
diff -u -p -r1.52 kz-http.c
--- src/net/kz-http.c	13 Feb 2005 22:55:15 -0000	1.52
+++ src/net/kz-http.c	23 Feb 2005 06:17:25 -0000
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #define __USE_XOPEN
 #include <time.h>
 #include <glib/gi18n.h>
@@ -206,6 +207,7 @@ kz_http_init (KzHTTP *http)
 	http->priv->header          = TRUE;
 	http->priv->chunked         = FALSE;
 	http->priv->redirection     = FALSE;
+	http->priv->location        = NULL;
 
 	http->priv->chunk_size      = 0;
 
@@ -392,26 +394,32 @@ kz_http_in_header(KzHTTP *http, GIOChann
 			}
 		}
 	}
-	else if (strncmp(buffer->str, "Content-Length:", 15) == 0)
+	else if (g_ascii_strncasecmp(buffer->str, "Content-Length:", 15) == 0)
 	{
 		guint size = (guint)strtol(buffer->str + 15, NULL, 10);
 		g_object_set(G_OBJECT(KZ_IO(http)),
 			     "file_size", size, NULL);
 	}
-	else if (strncmp(buffer->str, "Transfer-Encoding:", 18) == 0)
+	else if (g_ascii_strncasecmp(buffer->str, "Transfer-Encoding:", 18) == 0)
 	{
-		if(strncasecmp(buffer->str + 19, "chunked", 7) == 0)  
+		const gchar *value = buffer->str + 18;
+		while (*value && g_ascii_isspace(*value))
+			++value;
+		if (g_str_has_prefix(value, "chunked"))
 			kz_http_set_chunked_mode(http);
 	}
-	else if (strncmp(buffer->str, "Location:", 9) == 0)
+	else if (g_ascii_strncasecmp(buffer->str, "Location:", 9) == 0)
 	{
-		http->priv->location = g_strdup(buffer->str + 10);
+		const gchar *value = buffer->str + 18;
+		while (*value && g_ascii_isspace(*value))
+			++value;
+		http->priv->location = g_strdup(value);
 	}
-	else if (strncmp(buffer->str, "Last-Modified:", 15) == 0)
+	else if (g_ascii_strncasecmp(buffer->str, "Last-Modified:", 15) == 0)
 	{
 		struct tm t;
 		strptime(buffer->str + 15,
-			 "%a, %d %b %Y %H:%M:%S %z", &t);
+			 " %a, %d %b %Y %H:%M:%S %z", &t);
 		g_object_set(G_OBJECT(KZ_IO(http)),
 			     "last_modified", (guint)mktime(&t), NULL);
 	}
@@ -425,7 +433,6 @@ kz_http_in_header(KzHTTP *http, GIOChann
 	return iostatus;
 }
 
-
 static GIOStatus
 kz_http_in_chunked_body(KzHTTP *http, GIOChannel *iochannel)
 {


Kazehakase-devel メーリングリストの案内
Back to archive index