Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby
File: open-uri.rb
# frozen_string_literal: true
[0] Fix | Delete
require 'uri'
[1] Fix | Delete
require 'stringio'
[2] Fix | Delete
require 'time'
[3] Fix | Delete
[4] Fix | Delete
module Kernel
[5] Fix | Delete
private
[6] Fix | Delete
alias open_uri_original_open open # :nodoc:
[7] Fix | Delete
class << self
[8] Fix | Delete
alias open_uri_original_open open # :nodoc:
[9] Fix | Delete
end
[10] Fix | Delete
[11] Fix | Delete
def open(name, *rest, **kw, &block) # :nodoc:
[12] Fix | Delete
if (name.respond_to?(:open) && !name.respond_to?(:to_path)) ||
[13] Fix | Delete
(name.respond_to?(:to_str) &&
[14] Fix | Delete
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
[15] Fix | Delete
(uri = URI.parse(name)).respond_to?(:open))
[16] Fix | Delete
warn('calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open', uplevel: 1)
[17] Fix | Delete
URI.open(name, *rest, **kw, &block)
[18] Fix | Delete
else
[19] Fix | Delete
open_uri_original_open(name, *rest, **kw, &block)
[20] Fix | Delete
end
[21] Fix | Delete
end
[22] Fix | Delete
module_function :open
[23] Fix | Delete
end
[24] Fix | Delete
[25] Fix | Delete
module URI
[26] Fix | Delete
# Allows the opening of various resources including URIs.
[27] Fix | Delete
#
[28] Fix | Delete
# If the first argument responds to the 'open' method, 'open' is called on
[29] Fix | Delete
# it with the rest of the arguments.
[30] Fix | Delete
#
[31] Fix | Delete
# If the first argument is a string that begins with <code>(protocol)://<code>, it is parsed by
[32] Fix | Delete
# URI.parse. If the parsed object responds to the 'open' method,
[33] Fix | Delete
# 'open' is called on it with the rest of the arguments.
[34] Fix | Delete
#
[35] Fix | Delete
# Otherwise, Kernel#open is called.
[36] Fix | Delete
#
[37] Fix | Delete
# OpenURI::OpenRead#open provides URI::HTTP#open, URI::HTTPS#open and
[38] Fix | Delete
# URI::FTP#open, Kernel#open.
[39] Fix | Delete
#
[40] Fix | Delete
# We can accept URIs and strings that begin with http://, https:// and
[41] Fix | Delete
# ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
[42] Fix | Delete
def self.open(name, *rest, &block)
[43] Fix | Delete
if name.respond_to?(:open)
[44] Fix | Delete
name.open(*rest, &block)
[45] Fix | Delete
elsif name.respond_to?(:to_str) &&
[46] Fix | Delete
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
[47] Fix | Delete
(uri = URI.parse(name)).respond_to?(:open)
[48] Fix | Delete
uri.open(*rest, &block)
[49] Fix | Delete
else
[50] Fix | Delete
open_uri_original_open(name, *rest, &block)
[51] Fix | Delete
# After Kernel#open override is removed:
[52] Fix | Delete
#super
[53] Fix | Delete
end
[54] Fix | Delete
end
[55] Fix | Delete
end
[56] Fix | Delete
[57] Fix | Delete
# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
[58] Fix | Delete
#
[59] Fix | Delete
# == Example
[60] Fix | Delete
#
[61] Fix | Delete
# It is possible to open an http, https or ftp URL as though it were a file:
[62] Fix | Delete
#
[63] Fix | Delete
# URI.open("http://www.ruby-lang.org/") {|f|
[64] Fix | Delete
# f.each_line {|line| p line}
[65] Fix | Delete
# }
[66] Fix | Delete
#
[67] Fix | Delete
# The opened file has several getter methods for its meta-information, as
[68] Fix | Delete
# follows, since it is extended by OpenURI::Meta.
[69] Fix | Delete
#
[70] Fix | Delete
# URI.open("http://www.ruby-lang.org/en") {|f|
[71] Fix | Delete
# f.each_line {|line| p line}
[72] Fix | Delete
# p f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
[73] Fix | Delete
# p f.content_type # "text/html"
[74] Fix | Delete
# p f.charset # "iso-8859-1"
[75] Fix | Delete
# p f.content_encoding # []
[76] Fix | Delete
# p f.last_modified # Thu Dec 05 02:45:02 UTC 2002
[77] Fix | Delete
# }
[78] Fix | Delete
#
[79] Fix | Delete
# Additional header fields can be specified by an optional hash argument.
[80] Fix | Delete
#
[81] Fix | Delete
# URI.open("http://www.ruby-lang.org/en/",
[82] Fix | Delete
# "User-Agent" => "Ruby/#{RUBY_VERSION}",
[83] Fix | Delete
# "From" => "foo@bar.invalid",
[84] Fix | Delete
# "Referer" => "http://www.ruby-lang.org/") {|f|
[85] Fix | Delete
# # ...
[86] Fix | Delete
# }
[87] Fix | Delete
#
[88] Fix | Delete
# The environment variables such as http_proxy, https_proxy and ftp_proxy
[89] Fix | Delete
# are in effect by default. Here we disable proxy:
[90] Fix | Delete
#
[91] Fix | Delete
# URI.open("http://www.ruby-lang.org/en/", :proxy => nil) {|f|
[92] Fix | Delete
# # ...
[93] Fix | Delete
# }
[94] Fix | Delete
#
[95] Fix | Delete
# See OpenURI::OpenRead.open and URI.open for more on available options.
[96] Fix | Delete
#
[97] Fix | Delete
# URI objects can be opened in a similar way.
[98] Fix | Delete
#
[99] Fix | Delete
# uri = URI.parse("http://www.ruby-lang.org/en/")
[100] Fix | Delete
# uri.open {|f|
[101] Fix | Delete
# # ...
[102] Fix | Delete
# }
[103] Fix | Delete
#
[104] Fix | Delete
# URI objects can be read directly. The returned string is also extended by
[105] Fix | Delete
# OpenURI::Meta.
[106] Fix | Delete
#
[107] Fix | Delete
# str = uri.read
[108] Fix | Delete
# p str.base_uri
[109] Fix | Delete
#
[110] Fix | Delete
# Author:: Tanaka Akira <akr@m17n.org>
[111] Fix | Delete
[112] Fix | Delete
module OpenURI
[113] Fix | Delete
Options = {
[114] Fix | Delete
:proxy => true,
[115] Fix | Delete
:proxy_http_basic_authentication => true,
[116] Fix | Delete
:progress_proc => true,
[117] Fix | Delete
:content_length_proc => true,
[118] Fix | Delete
:http_basic_authentication => true,
[119] Fix | Delete
:read_timeout => true,
[120] Fix | Delete
:open_timeout => true,
[121] Fix | Delete
:ssl_ca_cert => nil,
[122] Fix | Delete
:ssl_verify_mode => nil,
[123] Fix | Delete
:ftp_active_mode => false,
[124] Fix | Delete
:redirect => true,
[125] Fix | Delete
:encoding => nil,
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
def OpenURI.check_options(options) # :nodoc:
[129] Fix | Delete
options.each {|k, v|
[130] Fix | Delete
next unless Symbol === k
[131] Fix | Delete
unless Options.include? k
[132] Fix | Delete
raise ArgumentError, "unrecognized option: #{k}"
[133] Fix | Delete
end
[134] Fix | Delete
}
[135] Fix | Delete
end
[136] Fix | Delete
[137] Fix | Delete
def OpenURI.scan_open_optional_arguments(*rest) # :nodoc:
[138] Fix | Delete
if !rest.empty? && (String === rest.first || Integer === rest.first)
[139] Fix | Delete
mode = rest.shift
[140] Fix | Delete
if !rest.empty? && Integer === rest.first
[141] Fix | Delete
perm = rest.shift
[142] Fix | Delete
end
[143] Fix | Delete
end
[144] Fix | Delete
return mode, perm, rest
[145] Fix | Delete
end
[146] Fix | Delete
[147] Fix | Delete
def OpenURI.open_uri(name, *rest) # :nodoc:
[148] Fix | Delete
uri = URI::Generic === name ? name : URI.parse(name)
[149] Fix | Delete
mode, _, rest = OpenURI.scan_open_optional_arguments(*rest)
[150] Fix | Delete
options = rest.shift if !rest.empty? && Hash === rest.first
[151] Fix | Delete
raise ArgumentError.new("extra arguments") if !rest.empty?
[152] Fix | Delete
options ||= {}
[153] Fix | Delete
OpenURI.check_options(options)
[154] Fix | Delete
[155] Fix | Delete
if /\Arb?(?:\Z|:([^:]+))/ =~ mode
[156] Fix | Delete
encoding, = $1,Encoding.find($1) if $1
[157] Fix | Delete
mode = nil
[158] Fix | Delete
end
[159] Fix | Delete
if options.has_key? :encoding
[160] Fix | Delete
if !encoding.nil?
[161] Fix | Delete
raise ArgumentError, "encoding specified twice"
[162] Fix | Delete
end
[163] Fix | Delete
encoding = Encoding.find(options[:encoding])
[164] Fix | Delete
end
[165] Fix | Delete
[166] Fix | Delete
unless mode == nil ||
[167] Fix | Delete
mode == 'r' || mode == 'rb' ||
[168] Fix | Delete
mode == File::RDONLY
[169] Fix | Delete
raise ArgumentError.new("invalid access mode #{mode} (#{uri.class} resource is read only.)")
[170] Fix | Delete
end
[171] Fix | Delete
[172] Fix | Delete
io = open_loop(uri, options)
[173] Fix | Delete
io.set_encoding(encoding) if encoding
[174] Fix | Delete
if block_given?
[175] Fix | Delete
begin
[176] Fix | Delete
yield io
[177] Fix | Delete
ensure
[178] Fix | Delete
if io.respond_to? :close!
[179] Fix | Delete
io.close! # Tempfile
[180] Fix | Delete
else
[181] Fix | Delete
io.close if !io.closed?
[182] Fix | Delete
end
[183] Fix | Delete
end
[184] Fix | Delete
else
[185] Fix | Delete
io
[186] Fix | Delete
end
[187] Fix | Delete
end
[188] Fix | Delete
[189] Fix | Delete
def OpenURI.open_loop(uri, options) # :nodoc:
[190] Fix | Delete
proxy_opts = []
[191] Fix | Delete
proxy_opts << :proxy_http_basic_authentication if options.include? :proxy_http_basic_authentication
[192] Fix | Delete
proxy_opts << :proxy if options.include? :proxy
[193] Fix | Delete
proxy_opts.compact!
[194] Fix | Delete
if 1 < proxy_opts.length
[195] Fix | Delete
raise ArgumentError, "multiple proxy options specified"
[196] Fix | Delete
end
[197] Fix | Delete
case proxy_opts.first
[198] Fix | Delete
when :proxy_http_basic_authentication
[199] Fix | Delete
opt_proxy, proxy_user, proxy_pass = options.fetch(:proxy_http_basic_authentication)
[200] Fix | Delete
proxy_user = proxy_user.to_str
[201] Fix | Delete
proxy_pass = proxy_pass.to_str
[202] Fix | Delete
if opt_proxy == true
[203] Fix | Delete
raise ArgumentError.new("Invalid authenticated proxy option: #{options[:proxy_http_basic_authentication].inspect}")
[204] Fix | Delete
end
[205] Fix | Delete
when :proxy
[206] Fix | Delete
opt_proxy = options.fetch(:proxy)
[207] Fix | Delete
proxy_user = nil
[208] Fix | Delete
proxy_pass = nil
[209] Fix | Delete
when nil
[210] Fix | Delete
opt_proxy = true
[211] Fix | Delete
proxy_user = nil
[212] Fix | Delete
proxy_pass = nil
[213] Fix | Delete
end
[214] Fix | Delete
case opt_proxy
[215] Fix | Delete
when true
[216] Fix | Delete
find_proxy = lambda {|u| pxy = u.find_proxy; pxy ? [pxy, nil, nil] : nil}
[217] Fix | Delete
when nil, false
[218] Fix | Delete
find_proxy = lambda {|u| nil}
[219] Fix | Delete
when String
[220] Fix | Delete
opt_proxy = URI.parse(opt_proxy)
[221] Fix | Delete
find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
[222] Fix | Delete
when URI::Generic
[223] Fix | Delete
find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
[224] Fix | Delete
else
[225] Fix | Delete
raise ArgumentError.new("Invalid proxy option: #{opt_proxy}")
[226] Fix | Delete
end
[227] Fix | Delete
[228] Fix | Delete
uri_set = {}
[229] Fix | Delete
buf = nil
[230] Fix | Delete
while true
[231] Fix | Delete
redirect = catch(:open_uri_redirect) {
[232] Fix | Delete
buf = Buffer.new
[233] Fix | Delete
uri.buffer_open(buf, find_proxy.call(uri), options)
[234] Fix | Delete
nil
[235] Fix | Delete
}
[236] Fix | Delete
if redirect
[237] Fix | Delete
if redirect.relative?
[238] Fix | Delete
# Although it violates RFC2616, Location: field may have relative
[239] Fix | Delete
# URI. It is converted to absolute URI using uri as a base URI.
[240] Fix | Delete
redirect = uri + redirect
[241] Fix | Delete
end
[242] Fix | Delete
if !options.fetch(:redirect, true)
[243] Fix | Delete
raise HTTPRedirect.new(buf.io.status.join(' '), buf.io, redirect)
[244] Fix | Delete
end
[245] Fix | Delete
unless OpenURI.redirectable?(uri, redirect)
[246] Fix | Delete
raise "redirection forbidden: #{uri} -> #{redirect}"
[247] Fix | Delete
end
[248] Fix | Delete
if options.include? :http_basic_authentication
[249] Fix | Delete
# send authentication only for the URI directly specified.
[250] Fix | Delete
options = options.dup
[251] Fix | Delete
options.delete :http_basic_authentication
[252] Fix | Delete
end
[253] Fix | Delete
uri = redirect
[254] Fix | Delete
raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s
[255] Fix | Delete
uri_set[uri.to_s] = true
[256] Fix | Delete
else
[257] Fix | Delete
break
[258] Fix | Delete
end
[259] Fix | Delete
end
[260] Fix | Delete
io = buf.io
[261] Fix | Delete
io.base_uri = uri
[262] Fix | Delete
io
[263] Fix | Delete
end
[264] Fix | Delete
[265] Fix | Delete
def OpenURI.redirectable?(uri1, uri2) # :nodoc:
[266] Fix | Delete
# This test is intended to forbid a redirection from http://... to
[267] Fix | Delete
# file:///etc/passwd, file:///dev/zero, etc. CVE-2011-1521
[268] Fix | Delete
# https to http redirect is also forbidden intentionally.
[269] Fix | Delete
# It avoids sending secure cookie or referer by non-secure HTTP protocol.
[270] Fix | Delete
# (RFC 2109 4.3.1, RFC 2965 3.3, RFC 2616 15.1.3)
[271] Fix | Delete
# However this is ad hoc. It should be extensible/configurable.
[272] Fix | Delete
uri1.scheme.downcase == uri2.scheme.downcase ||
[273] Fix | Delete
(/\A(?:http|ftp)\z/i =~ uri1.scheme && /\A(?:https?|ftp)\z/i =~ uri2.scheme)
[274] Fix | Delete
end
[275] Fix | Delete
[276] Fix | Delete
def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
[277] Fix | Delete
if proxy
[278] Fix | Delete
proxy_uri, proxy_user, proxy_pass = proxy
[279] Fix | Delete
raise "Non-HTTP proxy URI: #{proxy_uri}" if proxy_uri.class != URI::HTTP
[280] Fix | Delete
end
[281] Fix | Delete
[282] Fix | Delete
if target.userinfo
[283] Fix | Delete
raise ArgumentError, "userinfo not supported. [RFC3986]"
[284] Fix | Delete
end
[285] Fix | Delete
[286] Fix | Delete
header = {}
[287] Fix | Delete
options.each {|k, v| header[k] = v if String === k }
[288] Fix | Delete
[289] Fix | Delete
require 'net/http'
[290] Fix | Delete
klass = Net::HTTP
[291] Fix | Delete
if URI::HTTP === target
[292] Fix | Delete
# HTTP or HTTPS
[293] Fix | Delete
if proxy
[294] Fix | Delete
unless proxy_user && proxy_pass
[295] Fix | Delete
proxy_user, proxy_pass = proxy_uri.userinfo.split(':') if proxy_uri.userinfo
[296] Fix | Delete
end
[297] Fix | Delete
if proxy_user && proxy_pass
[298] Fix | Delete
klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port, proxy_user, proxy_pass)
[299] Fix | Delete
else
[300] Fix | Delete
klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port)
[301] Fix | Delete
end
[302] Fix | Delete
end
[303] Fix | Delete
target_host = target.hostname
[304] Fix | Delete
target_port = target.port
[305] Fix | Delete
request_uri = target.request_uri
[306] Fix | Delete
else
[307] Fix | Delete
# FTP over HTTP proxy
[308] Fix | Delete
target_host = proxy_uri.hostname
[309] Fix | Delete
target_port = proxy_uri.port
[310] Fix | Delete
request_uri = target.to_s
[311] Fix | Delete
if proxy_user && proxy_pass
[312] Fix | Delete
header["Proxy-Authorization"] =
[313] Fix | Delete
'Basic ' + ["#{proxy_user}:#{proxy_pass}"].pack('m0')
[314] Fix | Delete
end
[315] Fix | Delete
end
[316] Fix | Delete
[317] Fix | Delete
http = proxy ? klass.new(target_host, target_port) : klass.new(target_host, target_port, nil)
[318] Fix | Delete
if target.class == URI::HTTPS
[319] Fix | Delete
require 'net/https'
[320] Fix | Delete
http.use_ssl = true
[321] Fix | Delete
http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
[322] Fix | Delete
store = OpenSSL::X509::Store.new
[323] Fix | Delete
if options[:ssl_ca_cert]
[324] Fix | Delete
Array(options[:ssl_ca_cert]).each do |cert|
[325] Fix | Delete
if File.directory? cert
[326] Fix | Delete
store.add_path cert
[327] Fix | Delete
else
[328] Fix | Delete
store.add_file cert
[329] Fix | Delete
end
[330] Fix | Delete
end
[331] Fix | Delete
else
[332] Fix | Delete
store.set_default_paths
[333] Fix | Delete
end
[334] Fix | Delete
http.cert_store = store
[335] Fix | Delete
end
[336] Fix | Delete
if options.include? :read_timeout
[337] Fix | Delete
http.read_timeout = options[:read_timeout]
[338] Fix | Delete
end
[339] Fix | Delete
if options.include? :open_timeout
[340] Fix | Delete
http.open_timeout = options[:open_timeout]
[341] Fix | Delete
end
[342] Fix | Delete
[343] Fix | Delete
resp = nil
[344] Fix | Delete
http.start {
[345] Fix | Delete
req = Net::HTTP::Get.new(request_uri, header)
[346] Fix | Delete
if options.include? :http_basic_authentication
[347] Fix | Delete
user, pass = options[:http_basic_authentication]
[348] Fix | Delete
req.basic_auth user, pass
[349] Fix | Delete
end
[350] Fix | Delete
http.request(req) {|response|
[351] Fix | Delete
resp = response
[352] Fix | Delete
if options[:content_length_proc] && Net::HTTPSuccess === resp
[353] Fix | Delete
if resp.key?('Content-Length')
[354] Fix | Delete
options[:content_length_proc].call(resp['Content-Length'].to_i)
[355] Fix | Delete
else
[356] Fix | Delete
options[:content_length_proc].call(nil)
[357] Fix | Delete
end
[358] Fix | Delete
end
[359] Fix | Delete
resp.read_body {|str|
[360] Fix | Delete
buf << str
[361] Fix | Delete
if options[:progress_proc] && Net::HTTPSuccess === resp
[362] Fix | Delete
options[:progress_proc].call(buf.size)
[363] Fix | Delete
end
[364] Fix | Delete
str.clear
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
}
[368] Fix | Delete
io = buf.io
[369] Fix | Delete
io.rewind
[370] Fix | Delete
io.status = [resp.code, resp.message]
[371] Fix | Delete
resp.each_name {|name| buf.io.meta_add_field2 name, resp.get_fields(name) }
[372] Fix | Delete
case resp
[373] Fix | Delete
when Net::HTTPSuccess
[374] Fix | Delete
when Net::HTTPMovedPermanently, # 301
[375] Fix | Delete
Net::HTTPFound, # 302
[376] Fix | Delete
Net::HTTPSeeOther, # 303
[377] Fix | Delete
Net::HTTPTemporaryRedirect # 307
[378] Fix | Delete
begin
[379] Fix | Delete
loc_uri = URI.parse(resp['location'])
[380] Fix | Delete
rescue URI::InvalidURIError
[381] Fix | Delete
raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io)
[382] Fix | Delete
end
[383] Fix | Delete
throw :open_uri_redirect, loc_uri
[384] Fix | Delete
else
[385] Fix | Delete
raise OpenURI::HTTPError.new(io.status.join(' '), io)
[386] Fix | Delete
end
[387] Fix | Delete
end
[388] Fix | Delete
[389] Fix | Delete
class HTTPError < StandardError
[390] Fix | Delete
def initialize(message, io)
[391] Fix | Delete
super(message)
[392] Fix | Delete
@io = io
[393] Fix | Delete
end
[394] Fix | Delete
attr_reader :io
[395] Fix | Delete
end
[396] Fix | Delete
[397] Fix | Delete
# Raised on redirection,
[398] Fix | Delete
# only occurs when +redirect+ option for HTTP is +false+.
[399] Fix | Delete
class HTTPRedirect < HTTPError
[400] Fix | Delete
def initialize(message, io, uri)
[401] Fix | Delete
super(message, io)
[402] Fix | Delete
@uri = uri
[403] Fix | Delete
end
[404] Fix | Delete
attr_reader :uri
[405] Fix | Delete
end
[406] Fix | Delete
[407] Fix | Delete
class Buffer # :nodoc: all
[408] Fix | Delete
def initialize
[409] Fix | Delete
@io = StringIO.new
[410] Fix | Delete
@size = 0
[411] Fix | Delete
end
[412] Fix | Delete
attr_reader :size
[413] Fix | Delete
[414] Fix | Delete
StringMax = 10240
[415] Fix | Delete
def <<(str)
[416] Fix | Delete
@io << str
[417] Fix | Delete
@size += str.length
[418] Fix | Delete
if StringIO === @io && StringMax < @size
[419] Fix | Delete
require 'tempfile'
[420] Fix | Delete
io = Tempfile.new('open-uri')
[421] Fix | Delete
io.binmode
[422] Fix | Delete
Meta.init io, @io if Meta === @io
[423] Fix | Delete
io << @io.string
[424] Fix | Delete
@io = io
[425] Fix | Delete
end
[426] Fix | Delete
end
[427] Fix | Delete
[428] Fix | Delete
def io
[429] Fix | Delete
Meta.init @io unless Meta === @io
[430] Fix | Delete
@io
[431] Fix | Delete
end
[432] Fix | Delete
end
[433] Fix | Delete
[434] Fix | Delete
# Mixin for holding meta-information.
[435] Fix | Delete
module Meta
[436] Fix | Delete
def Meta.init(obj, src=nil) # :nodoc:
[437] Fix | Delete
obj.extend Meta
[438] Fix | Delete
obj.instance_eval {
[439] Fix | Delete
@base_uri = nil
[440] Fix | Delete
@meta = {} # name to string. legacy.
[441] Fix | Delete
@metas = {} # name to array of strings.
[442] Fix | Delete
}
[443] Fix | Delete
if src
[444] Fix | Delete
obj.status = src.status
[445] Fix | Delete
obj.base_uri = src.base_uri
[446] Fix | Delete
src.metas.each {|name, values|
[447] Fix | Delete
obj.meta_add_field2(name, values)
[448] Fix | Delete
}
[449] Fix | Delete
end
[450] Fix | Delete
end
[451] Fix | Delete
[452] Fix | Delete
# returns an Array that consists of status code and message.
[453] Fix | Delete
attr_accessor :status
[454] Fix | Delete
[455] Fix | Delete
# returns a URI that is the base of relative URIs in the data.
[456] Fix | Delete
# It may differ from the URI supplied by a user due to redirection.
[457] Fix | Delete
attr_accessor :base_uri
[458] Fix | Delete
[459] Fix | Delete
# returns a Hash that represents header fields.
[460] Fix | Delete
# The Hash keys are downcased for canonicalization.
[461] Fix | Delete
# The Hash values are a field body.
[462] Fix | Delete
# If there are multiple field with same field name,
[463] Fix | Delete
# the field values are concatenated with a comma.
[464] Fix | Delete
attr_reader :meta
[465] Fix | Delete
[466] Fix | Delete
# returns a Hash that represents header fields.
[467] Fix | Delete
# The Hash keys are downcased for canonicalization.
[468] Fix | Delete
# The Hash value are an array of field values.
[469] Fix | Delete
attr_reader :metas
[470] Fix | Delete
[471] Fix | Delete
def meta_setup_encoding # :nodoc:
[472] Fix | Delete
charset = self.charset
[473] Fix | Delete
enc = nil
[474] Fix | Delete
if charset
[475] Fix | Delete
begin
[476] Fix | Delete
enc = Encoding.find(charset)
[477] Fix | Delete
rescue ArgumentError
[478] Fix | Delete
end
[479] Fix | Delete
end
[480] Fix | Delete
enc = Encoding::ASCII_8BIT unless enc
[481] Fix | Delete
if self.respond_to? :force_encoding
[482] Fix | Delete
self.force_encoding(enc)
[483] Fix | Delete
elsif self.respond_to? :string
[484] Fix | Delete
self.string.force_encoding(enc)
[485] Fix | Delete
else # Tempfile
[486] Fix | Delete
self.set_encoding enc
[487] Fix | Delete
end
[488] Fix | Delete
end
[489] Fix | Delete
[490] Fix | Delete
def meta_add_field2(name, values) # :nodoc:
[491] Fix | Delete
name = name.downcase
[492] Fix | Delete
@metas[name] = values
[493] Fix | Delete
@meta[name] = values.join(', ')
[494] Fix | Delete
meta_setup_encoding if name == 'content-type'
[495] Fix | Delete
end
[496] Fix | Delete
[497] Fix | Delete
def meta_add_field(name, value) # :nodoc:
[498] Fix | Delete
meta_add_field2(name, [value])
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function