模块 OpenURI::Meta
用于保存元信息的 Mixin。
属性
返回一个 Array
,其中包含状态代码和消息。
公共实例方法
源码
# File lib/open-uri.rb, line 566 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 参数和代码块,则返回 nil,但 text 类型除外。在这种情况下,根据 RFC6838 4.2.1 的定义,返回“utf-8”。
源码
# File lib/open-uri.rb, line 583 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 字段中的编码列表。
这些编码会转换为小写以进行规范化。
源码
# File lib/open-uri.rb, line 551 def content_type type, *_ = content_type_parse type || 'application/octet-stream' end
返回 “type/subtype”,即 MIME Content-Type。它会转换为小写以进行规范化。Content-Type 参数会被剥离。
源码
# File lib/open-uri.rb, line 520 def last_modified if vs = @metas['last-modified'] v = vs.join(', ') Time.httpdate(v) else nil end end
返回一个 Time
,表示 Last-Modified 字段。