HTTP サーバのレスポンスヘッダは Firefox の Live HTTP headers よりも wget -S の方が詳しく取れる

December 12, 2008

#!/usr/bin/ruby
print “Content-Type:application/xhtml+xml\r\n”
print “Content-Type:text/plain\r\n\r\n”
print <<EOF
Test for
How to deal Content-Type
EOF

たとえば上記のようにわざと Content-Type を二重に出力してしまうと、Apache はバリデートで後者のみがクライアントに返されるが、lighttpd はそのまま二重定義で返してしまう。
これを確認するために、Firefox の Live HTTP headers を使ってレスポンスヘッダを見ても、下記のように Content-Type はどちらも1つしかない。lighttpd の前記の動作を確認することはできない。

Firefox Live HTTP headers

Apache

HTTP/1.x 200 OK
Date: Fri, 12 Dec 2008 15:23:14 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 34
Connection: close
Content-Type: text/plain; charset=UTF-8

lighttpd

HTTP/1.x 200 OK
Transfer-Encoding: chunked
Content-Type: text/plain
Date: Fri, 12 Dec 2008 15:23:55 GMT
Server: lighttpd/1.4.20

wget -S

今度は wget -S オプションで server response を見るようにしてみると、lighttpd の方は Content-Type がそのまま二重に出力されていることが確認できた。

Apache

$ wget -S http://localhost:80/type.cgi
–00:10:50– http://localhost/type.cgi
localhost をDNSに問いあわせています… 127.0.0.1
localhost|127.0.0.1|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています…
HTTP/1.1 200 OK
Date: Fri, 12 Dec 2008 15:10:50 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Content-Type: text/plain; charset=UTF-8
長さ: 特定できません [text/plain]
Saving to: type.cgi.1' \[ <=\> \] 34 --.-K/s in 0s 00:10:50 (566 KB/s) - type.cgi.1’ を保存しました [34]

lighttpd

$ wget -S http://localhost:81/type.cgi
–00:13:18– http://localhost:81/type.cgi
localhost をDNSに問いあわせています… 127.0.0.1
localhost|127.0.0.1|:81 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています…
HTTP/1.0 200 OK
Connection: close
Content-Type: application/xhtml+xml
Content-Type: text/plain
Date: Fri, 12 Dec 2008 15:13:18 GMT
Server: lighttpd/1.4.20
長さ: 特定できません [application/xhtml+xml]
Saving to: type.cgi.2' \[ <=\> \] 34 --.-K/s in 0s 00:13:18 (300 KB/s) - type.cgi.2’ を保存しました [34]

wget -S の方が Firefox Live HTTP headers より生のストリームに近いものを見ることができた。話が少しそれるが、Firefox は後の定義で、wget は先に現れた Content-Type で認識しているということもわかった。
ちなみにケータイ向けの CGI で、cgi.out({ “Content-Type” => “application/xhtml+XML” }) としていて、XHTML として認識されなかったのをデバッグしていた過程で気づいた。正しくは、cgi.out({ “type” => “application/xhtml+XML” }) としなくてはならない。そのため、カスタム定義と見なされて二つ出力されてしまっていた。

tilfin freelance software engineer