Module OpenURI::Meta
In: lib/open-uri.rb

Mixin for holding meta-information.

Methods

Constants

RE_LWS = /[\r\n\t ]+/n
RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n
RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n
RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n

Attributes

base_uri  [RW]  returns a URI which is base of relative URIs in the data. It may differ from the URI supplied by a user because redirection.
meta  [R]  returns a Hash which represents header fields. The Hash keys are downcased for canonicalization.
status  [RW]  returns an Array which consists status code and message.

Public Instance methods

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.

[Source]

     # File lib/open-uri.rb, line 407
407:     def charset
408:       type, *parameters = content_type_parse
409:       if pair = parameters.assoc('charset')
410:         pair.last.downcase
411:       elsif block_given?
412:         yield
413:       elsif type && %r{\Atext/} =~ type &&
414:             @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
415:         "iso-8859-1" # RFC2616 3.7.1
416:       else
417:         nil
418:       end
419:     end

returns a list of encodings in Content-Encoding field as an Array of String. The encodings are downcased for canonicalization.

[Source]

     # File lib/open-uri.rb, line 424
424:     def content_encoding
425:       v = @meta['content-encoding']
426:       if v && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ v
427:         v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase}
428:       else
429:         []
430:       end
431:     end

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

[Source]

     # File lib/open-uri.rb, line 392
392:     def content_type
393:       type, *parameters = content_type_parse
394:       type || 'application/octet-stream'
395:     end

returns a Time which represents Last-Modified field.

[Source]

     # File lib/open-uri.rb, line 359
359:     def last_modified
360:       if v = @meta['last-modified']
361:         Time.httpdate(v)
362:       else
363:         nil
364:       end
365:     end

[Validate]