Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • open-uri.rb

OpenURI::Meta

Mixin for holding meta-information.

Attributes

base_uri[RW]

returns a URI that is the base of relative URIs in the data. It may differ from the URI supplied by a user due to redirection.

meta[R]

returns a Hash that represents header fields. The Hash keys are downcased for canonicalization.

status[RW]

returns an Array that consists of status code and message.

Public Instance Methods

charset() click to toggle source

returns a charset parameter in Content-Type field. It is downcased for canonicalization.

If charset parameter is not given but a block is given, the block is called and its result is returned. It can be used to guess charset.

If charset parameter and block is not given, nil is returned except text type in HTTP. In that case, “iso-8859-1” is returned as defined by RFC2616 3.7.1.

 
               # File open-uri.rb, line 497
def charset
  type, *parameters = content_type_parse
  if pair = parameters.assoc('charset')
    pair.last.downcase
  elsif block_given?
    yield
  elsif type && %r{\Atext/} =~ type &&
        @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
    "iso-8859-1" # RFC2616 3.7.1
  else
    nil
  end
end
            
content_encoding() click to toggle source

Returns a list of encodings in Content-Encoding field as an array of strings.

The encodings are downcased for canonicalization.

 
               # File open-uri.rb, line 515
def content_encoding
  v = @meta['content-encoding']
  if v && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ v
    v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase}
  else
    []
  end
end
            
content_type() click to toggle source

returns “type/subtype” which is MIME Content-Type. It is downcased for canonicalization. Content-Type parameters are stripped.

 
               # File open-uri.rb, line 482
def content_type
  type, *_ = content_type_parse
  type || 'application/octet-stream'
end
            
last_modified() click to toggle source

returns a Time that represents the Last-Modified field.

 
               # File open-uri.rb, line 447
def last_modified
  if v = @meta['last-modified']
    Time.httpdate(v)
  else
    nil
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.