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 397
397:     def charset
398:       type, *parameters = content_type_parse
399:       if pair = parameters.assoc('charset')
400:         pair.last.downcase
401:       elsif block_given?
402:         yield
403:       elsif type && %r{\Atext/} =~ type &&
404:             @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
405:         "iso-8859-1" # RFC2616 3.7.1
406:       else
407:         nil
408:       end
409:     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 414
414:     def content_encoding
415:       v = @meta['content-encoding']
416:       if v && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ v
417:         v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase}
418:       else
419:         []
420:       end
421:     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 382
382:     def content_type
383:       type, *parameters = content_type_parse
384:       type || 'application/octet-stream'
385:     end

returns a Time which represents Last-Modified field.

[Source]

     # File lib/open-uri.rb, line 349
349:     def last_modified
350:       if v = @meta['last-modified']
351:         Time.httpdate(v)
352:       else
353:         nil
354:       end
355:     end

[Validate]