mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Update bundled Rack for Ruby 1.9 spec changes
This commit is contained in:
parent
0edb0a4fac
commit
524d8edf68
19 changed files with 51 additions and 51 deletions
|
@ -327,7 +327,7 @@ module ActionController
|
||||||
|
|
||||||
@headers = Rack::Utils::HeaderHash.new(headers)
|
@headers = Rack::Utils::HeaderHash.new(headers)
|
||||||
|
|
||||||
(@headers['Set-Cookie'] || []).each do |cookie|
|
(@headers['Set-Cookie'] || "").split("\n").each do |cookie|
|
||||||
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
|
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
|
||||||
@cookies[name] = value
|
@cookies[name] = value
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ module ActionController # :nodoc:
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@status = 200
|
@status = 200
|
||||||
@header = DEFAULT_HEADERS.dup
|
@header = Rack::Utils::HeaderHash.new(DEFAULT_HEADERS)
|
||||||
|
|
||||||
@writer = lambda { |x| @body << x }
|
@writer = lambda { |x| @body << x }
|
||||||
@block = nil
|
@block = nil
|
||||||
|
|
|
@ -139,12 +139,9 @@ module ActionController
|
||||||
cookie << "; HttpOnly" if options[:httponly]
|
cookie << "; HttpOnly" if options[:httponly]
|
||||||
|
|
||||||
headers = response[1]
|
headers = response[1]
|
||||||
case a = headers[SET_COOKIE]
|
unless headers[SET_COOKIE].blank?
|
||||||
when Array
|
headers[SET_COOKIE] << "\n#{cookie}"
|
||||||
a << cookie
|
else
|
||||||
when String
|
|
||||||
headers[SET_COOKIE] = [a, cookie]
|
|
||||||
when nil
|
|
||||||
headers[SET_COOKIE] = cookie
|
headers[SET_COOKIE] = cookie
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,12 +108,9 @@ module ActionController
|
||||||
end
|
end
|
||||||
|
|
||||||
cookie = build_cookie(@key, cookie.merge(options))
|
cookie = build_cookie(@key, cookie.merge(options))
|
||||||
case headers[HTTP_SET_COOKIE]
|
unless headers[HTTP_SET_COOKIE].blank?
|
||||||
when Array
|
headers[HTTP_SET_COOKIE] << "\n#{cookie}"
|
||||||
headers[HTTP_SET_COOKIE] << cookie
|
else
|
||||||
when String
|
|
||||||
headers[HTTP_SET_COOKIE] = [headers[HTTP_SET_COOKIE], cookie]
|
|
||||||
when nil
|
|
||||||
headers[HTTP_SET_COOKIE] = cookie
|
headers[HTTP_SET_COOKIE] = cookie
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -152,7 +152,7 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
content_type = content_type.to_s.strip # fixes a problem with extra '\r' with some browsers
|
content_type = content_type.to_s.strip # fixes a problem with extra '\r' with some browsers
|
||||||
|
|
||||||
headers.update(
|
headers.merge!(
|
||||||
'Content-Length' => options[:length],
|
'Content-Length' => options[:length],
|
||||||
'Content-Type' => content_type,
|
'Content-Type' => content_type,
|
||||||
'Content-Disposition' => disposition,
|
'Content-Disposition' => disposition,
|
||||||
|
|
|
@ -36,17 +36,19 @@ module Rack
|
||||||
mtime = headers.key?("Last-Modified") ?
|
mtime = headers.key?("Last-Modified") ?
|
||||||
Time.httpdate(headers["Last-Modified"]) : Time.now
|
Time.httpdate(headers["Last-Modified"]) : Time.now
|
||||||
body = self.class.gzip(body, mtime)
|
body = self.class.gzip(body, mtime)
|
||||||
headers = headers.merge("Content-Encoding" => "gzip", "Content-Length" => body.length.to_s)
|
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
|
||||||
|
headers = headers.merge("Content-Encoding" => "gzip", "Content-Length" => size.to_s)
|
||||||
[status, headers, [body]]
|
[status, headers, [body]]
|
||||||
when "deflate"
|
when "deflate"
|
||||||
body = self.class.deflate(body)
|
body = self.class.deflate(body)
|
||||||
headers = headers.merge("Content-Encoding" => "deflate", "Content-Length" => body.length.to_s)
|
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
|
||||||
|
headers = headers.merge("Content-Encoding" => "deflate", "Content-Length" => size.to_s)
|
||||||
[status, headers, [body]]
|
[status, headers, [body]]
|
||||||
when "identity"
|
when "identity"
|
||||||
[status, headers, body]
|
[status, headers, body]
|
||||||
when nil
|
when nil
|
||||||
message = ["An acceptable encoding for the requested resource #{request.fullpath} could not be found."]
|
message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
|
||||||
[406, {"Content-Type" => "text/plain", "Content-Length" => message[0].length.to_s}, message]
|
[406, {"Content-Type" => "text/plain", "Content-Length" => message.length.to_s}, [message]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Rack
|
||||||
def self.send_headers(status, headers)
|
def self.send_headers(status, headers)
|
||||||
STDOUT.print "Status: #{status}\r\n"
|
STDOUT.print "Status: #{status}\r\n"
|
||||||
headers.each { |k, vs|
|
headers.each { |k, vs|
|
||||||
vs.each { |v|
|
vs.split("\n").each { |v|
|
||||||
STDOUT.print "#{k}: #{v}\r\n"
|
STDOUT.print "#{k}: #{v}\r\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ module Rack
|
||||||
def self.send_headers(out, status, headers)
|
def self.send_headers(out, status, headers)
|
||||||
out.print "Status: #{status}\r\n"
|
out.print "Status: #{status}\r\n"
|
||||||
headers.each { |k, vs|
|
headers.each { |k, vs|
|
||||||
vs.each { |v|
|
vs.split("\n").each { |v|
|
||||||
out.print "#{k}: #{v}\r\n"
|
out.print "#{k}: #{v}\r\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ module Rack
|
||||||
def self.send_headers(status, headers)
|
def self.send_headers(status, headers)
|
||||||
print "Status: #{status}\r\n"
|
print "Status: #{status}\r\n"
|
||||||
headers.each { |k, vs|
|
headers.each { |k, vs|
|
||||||
vs.each { |v|
|
vs.split("\n").each { |v|
|
||||||
print "#{k}: #{v}\r\n"
|
print "#{k}: #{v}\r\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ module Rack
|
||||||
response.send_status(nil)
|
response.send_status(nil)
|
||||||
|
|
||||||
headers.each { |k, vs|
|
headers.each { |k, vs|
|
||||||
vs.each { |v|
|
vs.split("\n").each { |v|
|
||||||
response.header[k] = v
|
response.header[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Rack
|
||||||
begin
|
begin
|
||||||
socket.write("Status: #{status}\r\n")
|
socket.write("Status: #{status}\r\n")
|
||||||
headers.each do |k, vs|
|
headers.each do |k, vs|
|
||||||
vs.each {|v| socket.write("#{k}: #{v}\r\n")}
|
vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
|
||||||
end
|
end
|
||||||
socket.write("\r\n")
|
socket.write("\r\n")
|
||||||
body.each {|s| socket.write(s)}
|
body.each {|s| socket.write(s)}
|
||||||
|
|
|
@ -42,9 +42,9 @@ module Rack
|
||||||
res.status = status.to_i
|
res.status = status.to_i
|
||||||
headers.each { |k, vs|
|
headers.each { |k, vs|
|
||||||
if k.downcase == "set-cookie"
|
if k.downcase == "set-cookie"
|
||||||
res.cookies.concat Array(vs)
|
res.cookies.concat vs.split("\n")
|
||||||
else
|
else
|
||||||
vs.each { |v|
|
vs.split("\n").each { |v|
|
||||||
res[k] = v
|
res[k] = v
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -338,16 +338,13 @@ module Rack
|
||||||
## but only contain keys that consist of
|
## but only contain keys that consist of
|
||||||
## letters, digits, <tt>_</tt> or <tt>-</tt> and start with a letter.
|
## letters, digits, <tt>_</tt> or <tt>-</tt> and start with a letter.
|
||||||
assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ }
|
assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ }
|
||||||
##
|
|
||||||
## The values of the header must respond to #each.
|
## The values of the header must be Strings,
|
||||||
assert("header values must respond to #each, but the value of " +
|
assert("a header value must be a String, but the value of " +
|
||||||
"'#{key}' doesn't (is #{value.class})") { value.respond_to? :each }
|
"'#{key}' is a #{value.class}") { value.kind_of? String }
|
||||||
value.each { |item|
|
## consisting of lines (for multiple header values) seperated by "\n".
|
||||||
## The values passed on #each must be Strings
|
value.split("\n").each { |item|
|
||||||
assert("header values must consist of Strings, but '#{key}' also contains a #{item.class}") {
|
## The lines must not contain characters below 037.
|
||||||
item.instance_of?(String)
|
|
||||||
}
|
|
||||||
## and not contain characters below 037.
|
|
||||||
assert("invalid header value #{key}: #{item.inspect}") {
|
assert("invalid header value #{key}: #{item.inspect}") {
|
||||||
item !~ /[\000-\037]/
|
item !~ /[\000-\037]/
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,9 +118,7 @@ module Rack
|
||||||
@original_headers = headers
|
@original_headers = headers
|
||||||
@headers = Rack::Utils::HeaderHash.new
|
@headers = Rack::Utils::HeaderHash.new
|
||||||
headers.each { |field, values|
|
headers.each { |field, values|
|
||||||
values.each { |value|
|
@headers[field] = values
|
||||||
@headers[field] = value
|
|
||||||
}
|
|
||||||
@headers[field] = "" if values.empty?
|
@headers[field] = "" if values.empty?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,14 @@ module Rack
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
{}.replace(self)
|
inject({}) do |hash, (k,v)|
|
||||||
|
if v.respond_to? :to_ary
|
||||||
|
hash[k] = v.to_ary.join("\n")
|
||||||
|
else
|
||||||
|
hash[k] = v
|
||||||
|
end
|
||||||
|
hash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](k)
|
def [](k)
|
||||||
|
|
|
@ -90,7 +90,7 @@ module ActionController #:nodoc:
|
||||||
def verify_action(options) #:nodoc:
|
def verify_action(options) #:nodoc:
|
||||||
if prereqs_invalid?(options)
|
if prereqs_invalid?(options)
|
||||||
flash.update(options[:add_flash]) if options[:add_flash]
|
flash.update(options[:add_flash]) if options[:add_flash]
|
||||||
response.headers.update(options[:add_headers]) if options[:add_headers]
|
response.headers.merge!(options[:add_headers]) if options[:add_headers]
|
||||||
apply_remaining_actions(options) unless performed?
|
apply_remaining_actions(options) unless performed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -296,7 +296,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
||||||
assert_equal "Gone", status_message
|
assert_equal "Gone", status_message
|
||||||
assert_response 410
|
assert_response 410
|
||||||
assert_response :gone
|
assert_response :gone
|
||||||
assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers["Set-Cookie"]
|
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
|
||||||
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
|
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
|
||||||
assert_equal "Gone", response.body
|
assert_equal "Gone", response.body
|
||||||
end
|
end
|
||||||
|
|
|
@ -219,7 +219,7 @@ class RackResponseTest < BaseRackTest
|
||||||
"Content-Type" => "text/html; charset=utf-8",
|
"Content-Type" => "text/html; charset=utf-8",
|
||||||
"Cache-Control" => "private, max-age=0, must-revalidate",
|
"Cache-Control" => "private, max-age=0, must-revalidate",
|
||||||
"ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
|
"ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
|
||||||
"Set-Cookie" => [],
|
"Set-Cookie" => "",
|
||||||
"Content-Length" => "13"
|
"Content-Length" => "13"
|
||||||
}, headers)
|
}, headers)
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ class RackResponseTest < BaseRackTest
|
||||||
"Content-Type" => "text/html; charset=utf-8",
|
"Content-Type" => "text/html; charset=utf-8",
|
||||||
"Cache-Control" => "private, max-age=0, must-revalidate",
|
"Cache-Control" => "private, max-age=0, must-revalidate",
|
||||||
"ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
|
"ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
|
||||||
"Set-Cookie" => [],
|
"Set-Cookie" => "",
|
||||||
"Content-Length" => "8"
|
"Content-Length" => "8"
|
||||||
}, headers)
|
}, headers)
|
||||||
end
|
end
|
||||||
|
@ -254,7 +254,7 @@ class RackResponseTest < BaseRackTest
|
||||||
assert_equal({
|
assert_equal({
|
||||||
"Content-Type" => "text/html; charset=utf-8",
|
"Content-Type" => "text/html; charset=utf-8",
|
||||||
"Cache-Control" => "no-cache",
|
"Cache-Control" => "no-cache",
|
||||||
"Set-Cookie" => []
|
"Set-Cookie" => ""
|
||||||
}, headers)
|
}, headers)
|
||||||
|
|
||||||
parts = []
|
parts = []
|
||||||
|
|
|
@ -96,7 +96,7 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
with_test_route_set do
|
with_test_route_set do
|
||||||
get '/set_session_value'
|
get '/set_session_value'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal ["_myapp_session=#{response.body}; path=/; HttpOnly"],
|
assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
|
||||||
headers['Set-Cookie']
|
headers['Set-Cookie']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -145,7 +145,7 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
with_test_route_set do
|
with_test_route_set do
|
||||||
get '/no_session_access'
|
get '/no_session_access'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal [], headers['Set-Cookie']
|
assert_equal "", headers['Set-Cookie']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
"fef868465920f415f2c0652d6910d3af288a0367"
|
"fef868465920f415f2c0652d6910d3af288a0367"
|
||||||
get '/no_session_access'
|
get '/no_session_access'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal [], headers['Set-Cookie']
|
assert_equal "", headers['Set-Cookie']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
get '/set_session_value'
|
get '/set_session_value'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
session_payload = response.body
|
session_payload = response.body
|
||||||
assert_equal ["_myapp_session=#{response.body}; path=/; HttpOnly"],
|
assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
|
||||||
headers['Set-Cookie']
|
headers['Set-Cookie']
|
||||||
|
|
||||||
get '/call_reset_session'
|
get '/call_reset_session'
|
||||||
|
@ -209,7 +209,8 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
cookie_body = response.body
|
cookie_body = response.body
|
||||||
assert_equal ["_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly"], headers['Set-Cookie']
|
assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
|
||||||
|
headers['Set-Cookie']
|
||||||
|
|
||||||
# Second request does not access the session
|
# Second request does not access the session
|
||||||
time = Time.local(2008, 4, 25)
|
time = Time.local(2008, 4, 25)
|
||||||
|
@ -219,7 +220,8 @@ class CookieStoreTest < ActionController::IntegrationTest
|
||||||
get '/no_session_access'
|
get '/no_session_access'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
assert_equal ["_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly"], headers['Set-Cookie']
|
assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
|
||||||
|
headers['Set-Cookie']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue