# Open-uri $B$N(B content\_type

**URL:** <https://www.ruby-forum.com/t/open-uri-b-n-b-content-type/171509>\
**Category:** Development\
**Created:** [July 3, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/open-uri-b-n-b-content-type/171509 "2009-07-03T19:19:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@Kazuhiro\_NISHIYAMA](https://www.ruby-forum.com/u/Kazuhiro_NISHIYAMA)\
**Post date:** [July 3, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/open-uri-b-n-b-content-type/171509/1 "2009-07-03T19:19:28Z")

</div>

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
