module OpenURI::Meta
用于保存元信息的混合模块。
属性
返回一个包含状态码和消息的 Array。
Public Instance Methods
Source
# File lib/open-uri.rb, line 572 def charset type, *parameters = content_type_parse if pair = parameters.assoc('charset') pair.last.downcase elsif block_given? yield elsif type && %r{\Atext/} =~ type "utf-8" # RFC6838 4.2.1 else nil end end
返回 Content-Type 字段中的 charset 参数。为了规范化,该参数被转换为小写。
如果未提供 charset 参数但提供了代码块,则会调用该代码块并返回其结果。这可用于猜测 charset。
如果未提供 charset 参数和代码块,则返回 nil,除非是文本类型。在这种情况下,根据 RFC6838 4.2.1 的定义,返回 "utf-8"。
Source
# File lib/open-uri.rb, line 589 def content_encoding vs = @metas['content-encoding'] if vs && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ (v = vs.join(', ')) v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase} else [] end end
以字符串数组的形式返回 Content-Encoding 字段中的编码列表。
为了规范化,编码被转换为小写。
Source
# File lib/open-uri.rb, line 557 def content_type type, *_ = content_type_parse type || 'application/octet-stream' end
返回 MIME Content-Type 的 "type/subtype"。为了规范化,该值被转换为小写。 Content-Type 参数被剥离。
Source
# File lib/open-uri.rb, line 526 def last_modified if vs = @metas['last-modified'] v = vs.join(', ') Time.httpdate(v) else nil end end
返回一个代表 Last-Modified 字段的 Time 对象。