| Module | OpenURI::Meta |
| In: |
lib/open-uri.rb
|
Mixin for holding meta-information.
| 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 |
| 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. |
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 lib/open-uri.rb, line 398
398: def charset
399: type, *parameters = content_type_parse
400: if pair = parameters.assoc('charset')
401: pair.last.downcase
402: elsif block_given?
403: yield
404: elsif type && %r{\Atext/} =~ type &&
405: @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
406: "iso-8859-1" # RFC2616 3.7.1
407: else
408: nil
409: end
410: end
returns a list of encodings in Content-Encoding field as an Array of String. The encodings are downcased for canonicalization.
# File lib/open-uri.rb, line 415
415: def content_encoding
416: v = @meta['content-encoding']
417: if v && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ v
418: v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase}
419: else
420: []
421: end
422: end
returns "type/subtype" which is MIME Content-Type. It is downcased for canonicalization. Content-Type parameters are stripped.
# File lib/open-uri.rb, line 383
383: def content_type
384: type, *parameters = content_type_parse
385: type || 'application/octet-stream'
386: end