e$B@>;3OB9-$G$9!#e(B
e$B0J2<$N$h$&$KE,Ev$Je(B FC2 e$B$N%V%m%0$re(B open-uri e$B$G3+$/$He(B
content_type e$B$,e(B
“application/octet-stream” e$B$K$J$C$F$7$^$$$^$9!#e(B
“text/html” e$B$,JV$C$F$-$F$[$7$$$H;W$C$?$N$G$9$,!"$I$&$G$7$g$&$+e(B?
% cat a.rb
#!/usr/bin/env ruby
require ‘open-uri’
open(“http://(e$BN,e(B).fc2.com/”) do |f|
p f.content_type
p f.meta[“content-type”]
end
% ruby a.rb
“application/octet-stream”
“text/html, text/html;charset=euc-jp”
% w3m -dump_head http://(e$BN,e(B).fc2.com/ | grep Content-Type
Content-Type: text/html
Content-Type: text/html;charset=euc-jp
%
w3m -dump_head e$B$N$h$&$KD>@%l%9%]%s%9%X%C%@$r$$F$$k$He(B
Content-Type e$B$,e(B2e$B9TJV$C$F$-$F$$$F!"e(Bopen-uri e$B$Ne(B
resp.each {|name,value| buf.io.meta_add_field name, value }
e$B$H$$$&=hM}$r$$k$H8e$,M%@h$5$l$k$N$+$H;W$C$?$N$G$9$,!"e(B
e$B99$Ke(B net/http.rb e$B$NJ}$r$$F$_$k$H!"e(B
def [](key)
a = @header[key.downcase] or return nil
a.join(', ')
end
e$B$H$J$C$F$$$F!"e(Bmeta_add_field e$B$K$O4{$Ke(B join(’, ')
e$B$5$l$F$7$^$C$F$$$ke(B
e$BJ8;zNs$,EO$C$F$-$F$$$k$h$&$G$9!#e(B