2009-04-26 11:26:53 -04:00
|
|
|
require 'abstract_unit'
|
2014-09-03 11:16:37 -04:00
|
|
|
require 'timeout'
|
|
|
|
require 'rack/content_length'
|
2009-04-26 11:26:53 -04:00
|
|
|
|
|
|
|
class ResponseTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
2015-09-23 17:39:45 -04:00
|
|
|
@response = ActionDispatch::Response.create
|
2015-12-01 14:28:01 -05:00
|
|
|
@response.request = ActionDispatch::Request.empty
|
2009-04-26 11:26:53 -04:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:54:11 -04:00
|
|
|
def test_can_wait_until_commit
|
|
|
|
t = Thread.new {
|
2012-07-28 12:12:35 -04:00
|
|
|
@response.await_commit
|
2012-07-27 18:54:11 -04:00
|
|
|
}
|
|
|
|
@response.commit!
|
|
|
|
assert @response.committed?
|
2012-07-28 12:12:35 -04:00
|
|
|
assert t.join(0.5)
|
2012-07-27 18:54:11 -04:00
|
|
|
end
|
|
|
|
|
2012-07-29 18:51:21 -04:00
|
|
|
def test_stream_close
|
|
|
|
@response.stream.close
|
|
|
|
assert @response.stream.closed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_stream_write
|
|
|
|
@response.stream.write "foo"
|
|
|
|
@response.stream.close
|
|
|
|
assert_equal "foo", @response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_write_after_close
|
|
|
|
@response.stream.close
|
|
|
|
|
|
|
|
e = assert_raises(IOError) do
|
|
|
|
@response.stream.write "omg"
|
|
|
|
end
|
|
|
|
assert_equal "closed stream", e.message
|
|
|
|
end
|
|
|
|
|
2016-01-05 21:13:40 -05:00
|
|
|
def test_read_body_during_action
|
|
|
|
@response.body = "Hello, World!"
|
|
|
|
|
|
|
|
# even though there's no explicitly set content-type,
|
|
|
|
assert_equal nil, @response.content_type
|
|
|
|
|
|
|
|
# after the action reads back @response.body,
|
|
|
|
assert_equal "Hello, World!", @response.body
|
|
|
|
|
|
|
|
# the response can be built.
|
|
|
|
status, headers, body = @response.to_a
|
|
|
|
assert_equal 200, status
|
|
|
|
assert_equal({
|
|
|
|
"Content-Type" => "text/html; charset=utf-8"
|
|
|
|
}, headers)
|
|
|
|
|
|
|
|
parts = []
|
|
|
|
body.each { |part| parts << part }
|
|
|
|
assert_equal ["Hello, World!"], parts
|
|
|
|
end
|
|
|
|
|
2011-12-12 22:45:16 -05:00
|
|
|
def test_response_body_encoding
|
2013-01-28 02:59:50 -05:00
|
|
|
body = ["hello".encode(Encoding::UTF_8)]
|
2011-12-12 22:45:16 -05:00
|
|
|
response = ActionDispatch::Response.new 200, {}, body
|
2015-12-01 14:28:01 -05:00
|
|
|
response.request = ActionDispatch::Request.empty
|
2011-12-12 22:45:16 -05:00
|
|
|
assert_equal Encoding::UTF_8, response.body.encoding
|
|
|
|
end
|
|
|
|
|
2015-06-16 17:58:50 -04:00
|
|
|
def test_response_charset_writer
|
|
|
|
@response.charset = 'utf-16'
|
|
|
|
assert_equal 'utf-16', @response.charset
|
|
|
|
@response.charset = nil
|
|
|
|
assert_equal 'utf-8', @response.charset
|
|
|
|
end
|
|
|
|
|
2015-09-08 19:13:54 -04:00
|
|
|
def test_setting_content_type_header_impacts_content_type_method
|
|
|
|
@response.headers['Content-Type'] = "application/aaron"
|
|
|
|
assert_equal 'application/aaron', @response.content_type
|
|
|
|
end
|
|
|
|
|
2009-04-26 11:26:53 -04:00
|
|
|
test "simple output" do
|
|
|
|
@response.body = "Hello, World!"
|
|
|
|
|
|
|
|
status, headers, body = @response.to_a
|
|
|
|
assert_equal 200, status
|
|
|
|
assert_equal({
|
2010-09-22 15:40:14 -04:00
|
|
|
"Content-Type" => "text/html; charset=utf-8"
|
2009-04-26 11:26:53 -04:00
|
|
|
}, headers)
|
|
|
|
|
|
|
|
parts = []
|
|
|
|
body.each { |part| parts << part }
|
|
|
|
assert_equal ["Hello, World!"], parts
|
|
|
|
end
|
2011-02-07 19:44:27 -05:00
|
|
|
|
2010-10-18 15:00:48 -04:00
|
|
|
test "status handled properly in initialize" do
|
|
|
|
assert_equal 200, ActionDispatch::Response.new('200 OK').status
|
|
|
|
end
|
2009-04-26 11:26:53 -04:00
|
|
|
|
2015-09-08 18:37:33 -04:00
|
|
|
def test_only_set_charset_still_defaults_to_text_html
|
|
|
|
response = ActionDispatch::Response.new
|
|
|
|
response.charset = "utf-16"
|
|
|
|
_,headers,_ = response.to_a
|
|
|
|
assert_equal "text/html; charset=utf-16", headers['Content-Type']
|
|
|
|
end
|
|
|
|
|
2009-04-26 11:26:53 -04:00
|
|
|
test "utf8 output" do
|
|
|
|
@response.body = [1090, 1077, 1089, 1090].pack("U*")
|
|
|
|
|
2011-02-07 19:44:27 -05:00
|
|
|
status, headers, _ = @response.to_a
|
2009-04-26 11:26:53 -04:00
|
|
|
assert_equal 200, status
|
|
|
|
assert_equal({
|
2010-09-22 15:40:14 -04:00
|
|
|
"Content-Type" => "text/html; charset=utf-8"
|
2009-04-26 11:26:53 -04:00
|
|
|
}, headers)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "content type" do
|
|
|
|
[204, 304].each do |c|
|
2015-06-15 20:54:08 -04:00
|
|
|
@response = ActionDispatch::Response.new
|
2009-04-26 11:26:53 -04:00
|
|
|
@response.status = c.to_s
|
2011-02-07 19:44:27 -05:00
|
|
|
_, headers, _ = @response.to_a
|
2009-04-26 11:26:53 -04:00
|
|
|
assert !headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
|
|
|
|
end
|
|
|
|
|
|
|
|
[200, 302, 404, 500].each do |c|
|
2015-06-15 20:54:08 -04:00
|
|
|
@response = ActionDispatch::Response.new
|
2009-04-26 11:26:53 -04:00
|
|
|
@response.status = c.to_s
|
2011-02-07 19:44:27 -05:00
|
|
|
_, headers, _ = @response.to_a
|
2009-04-26 11:26:53 -04:00
|
|
|
assert headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not include Status header" do
|
|
|
|
@response.status = "200 OK"
|
2011-02-07 19:44:27 -05:00
|
|
|
_, headers, _ = @response.to_a
|
2009-04-26 11:26:53 -04:00
|
|
|
assert !headers.has_key?('Status')
|
|
|
|
end
|
2009-04-26 12:12:33 -04:00
|
|
|
|
|
|
|
test "response code" do
|
|
|
|
@response.status = "200 OK"
|
|
|
|
assert_equal 200, @response.response_code
|
|
|
|
|
|
|
|
@response.status = "200"
|
|
|
|
assert_equal 200, @response.response_code
|
|
|
|
|
|
|
|
@response.status = 200
|
|
|
|
assert_equal 200, @response.response_code
|
|
|
|
end
|
|
|
|
|
|
|
|
test "code" do
|
|
|
|
@response.status = "200 OK"
|
|
|
|
assert_equal "200", @response.code
|
|
|
|
|
|
|
|
@response.status = "200"
|
|
|
|
assert_equal "200", @response.code
|
|
|
|
|
|
|
|
@response.status = 200
|
|
|
|
assert_equal "200", @response.code
|
|
|
|
end
|
|
|
|
|
|
|
|
test "message" do
|
|
|
|
@response.status = "200 OK"
|
|
|
|
assert_equal "OK", @response.message
|
|
|
|
|
|
|
|
@response.status = "200"
|
|
|
|
assert_equal "OK", @response.message
|
|
|
|
|
|
|
|
@response.status = 200
|
|
|
|
assert_equal "OK", @response.message
|
|
|
|
end
|
|
|
|
|
|
|
|
test "cookies" do
|
|
|
|
@response.set_cookie("user_name", :value => "david", :path => "/")
|
2015-10-03 02:50:52 -04:00
|
|
|
_status, headers, _body = @response.to_a
|
2009-04-26 12:12:33 -04:00
|
|
|
assert_equal "user_name=david; path=/", headers["Set-Cookie"]
|
|
|
|
assert_equal({"user_name" => "david"}, @response.cookies)
|
2015-09-23 14:25:33 -04:00
|
|
|
end
|
2009-04-26 12:12:33 -04:00
|
|
|
|
2015-09-23 14:25:33 -04:00
|
|
|
test "multiple cookies" do
|
2015-09-23 14:23:13 -04:00
|
|
|
@response.set_cookie("user_name", :value => "david", :path => "/")
|
2009-04-26 12:12:33 -04:00
|
|
|
@response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5))
|
2015-10-03 02:50:52 -04:00
|
|
|
_status, headers, _body = @response.to_a
|
2013-01-10 22:34:52 -05:00
|
|
|
assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000", headers["Set-Cookie"]
|
2009-04-26 12:12:33 -04:00
|
|
|
assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies)
|
2015-09-23 14:25:33 -04:00
|
|
|
end
|
2010-05-17 19:42:35 -04:00
|
|
|
|
2015-09-23 14:25:33 -04:00
|
|
|
test "delete cookies" do
|
|
|
|
@response.set_cookie("user_name", :value => "david", :path => "/")
|
|
|
|
@response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5))
|
2010-05-17 19:42:35 -04:00
|
|
|
@response.delete_cookie("login")
|
|
|
|
assert_equal({"user_name" => "david", "login" => nil}, @response.cookies)
|
2009-04-26 12:12:33 -04:00
|
|
|
end
|
2009-12-17 23:10:06 -05:00
|
|
|
|
|
|
|
test "read cache control" do
|
2010-09-27 14:18:35 -04:00
|
|
|
resp = ActionDispatch::Response.new.tap { |response|
|
|
|
|
response.cache_control[:public] = true
|
|
|
|
response.etag = '123'
|
|
|
|
response.body = 'Hello'
|
2009-12-17 23:10:06 -05:00
|
|
|
}
|
|
|
|
resp.to_a
|
|
|
|
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.etag)
|
2009-12-17 23:10:06 -05:00
|
|
|
assert_equal({:public => true}, resp.cache_control)
|
|
|
|
|
|
|
|
assert_equal('public', resp.headers['Cache-Control'])
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.headers['ETag'])
|
2009-12-17 23:10:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "read charset and content type" do
|
2010-09-27 14:18:35 -04:00
|
|
|
resp = ActionDispatch::Response.new.tap { |response|
|
|
|
|
response.charset = 'utf-16'
|
2015-10-05 01:14:04 -04:00
|
|
|
response.content_type = Mime[:xml]
|
2010-09-27 14:18:35 -04:00
|
|
|
response.body = 'Hello'
|
2009-12-17 23:10:06 -05:00
|
|
|
}
|
|
|
|
resp.to_a
|
|
|
|
|
|
|
|
assert_equal('utf-16', resp.charset)
|
2015-10-05 01:14:04 -04:00
|
|
|
assert_equal(Mime[:xml], resp.content_type)
|
2009-12-17 23:10:06 -05:00
|
|
|
|
|
|
|
assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type'])
|
|
|
|
end
|
2011-12-06 11:46:41 -05:00
|
|
|
|
2015-10-01 15:57:23 -04:00
|
|
|
test "read content type with default charset utf-8" do
|
|
|
|
original = ActionDispatch::Response.default_charset
|
|
|
|
begin
|
|
|
|
resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" })
|
|
|
|
assert_equal('utf-8', resp.charset)
|
|
|
|
ensure
|
|
|
|
ActionDispatch::Response.default_charset = original
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "read content type with charset utf-16" do
|
2011-12-06 11:46:41 -05:00
|
|
|
original = ActionDispatch::Response.default_charset
|
|
|
|
begin
|
|
|
|
ActionDispatch::Response.default_charset = 'utf-16'
|
2015-03-01 06:28:25 -05:00
|
|
|
resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" })
|
2011-12-06 11:46:41 -05:00
|
|
|
assert_equal('utf-16', resp.charset)
|
|
|
|
ensure
|
|
|
|
ActionDispatch::Response.default_charset = original
|
|
|
|
end
|
|
|
|
end
|
2012-08-09 10:12:11 -04:00
|
|
|
|
2012-08-18 18:29:58 -04:00
|
|
|
test "read x_frame_options, x_content_type_options and x_xss_protection" do
|
2014-06-05 10:52:13 -04:00
|
|
|
original_default_headers = ActionDispatch::Response.default_headers
|
2012-09-08 15:51:22 -04:00
|
|
|
begin
|
|
|
|
ActionDispatch::Response.default_headers = {
|
|
|
|
'X-Frame-Options' => 'DENY',
|
|
|
|
'X-Content-Type-Options' => 'nosniff',
|
2013-06-13 15:56:02 -04:00
|
|
|
'X-XSS-Protection' => '1;'
|
2012-09-08 15:51:22 -04:00
|
|
|
}
|
2015-09-23 17:39:45 -04:00
|
|
|
resp = ActionDispatch::Response.create.tap { |response|
|
2012-09-08 15:51:22 -04:00
|
|
|
response.body = 'Hello'
|
|
|
|
}
|
|
|
|
resp.to_a
|
|
|
|
|
|
|
|
assert_equal('DENY', resp.headers['X-Frame-Options'])
|
|
|
|
assert_equal('nosniff', resp.headers['X-Content-Type-Options'])
|
|
|
|
assert_equal('1;', resp.headers['X-XSS-Protection'])
|
|
|
|
ensure
|
2014-06-05 10:52:13 -04:00
|
|
|
ActionDispatch::Response.default_headers = original_default_headers
|
2012-09-08 15:51:22 -04:00
|
|
|
end
|
|
|
|
end
|
2012-08-09 10:12:11 -04:00
|
|
|
|
|
|
|
test "read custom default_header" do
|
2014-06-05 10:52:13 -04:00
|
|
|
original_default_headers = ActionDispatch::Response.default_headers
|
2012-09-08 15:51:22 -04:00
|
|
|
begin
|
|
|
|
ActionDispatch::Response.default_headers = {
|
|
|
|
'X-XX-XXXX' => 'Here is my phone number'
|
|
|
|
}
|
2015-09-23 17:39:45 -04:00
|
|
|
resp = ActionDispatch::Response.create.tap { |response|
|
2012-09-08 15:51:22 -04:00
|
|
|
response.body = 'Hello'
|
|
|
|
}
|
|
|
|
resp.to_a
|
|
|
|
|
|
|
|
assert_equal('Here is my phone number', resp.headers['X-XX-XXXX'])
|
|
|
|
ensure
|
2014-06-05 10:52:13 -04:00
|
|
|
ActionDispatch::Response.default_headers = original_default_headers
|
2012-09-08 15:51:22 -04:00
|
|
|
end
|
|
|
|
end
|
2013-08-16 11:22:08 -04:00
|
|
|
|
|
|
|
test "respond_to? accepts include_private" do
|
|
|
|
assert_not @response.respond_to?(:method_missing)
|
|
|
|
assert @response.respond_to?(:method_missing, true)
|
|
|
|
end
|
2014-02-02 17:55:35 -05:00
|
|
|
|
2014-09-05 16:33:20 -04:00
|
|
|
test "can be explicitly destructured into status, headers and an enumerable body" do
|
2014-02-02 17:55:35 -05:00
|
|
|
response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found'])
|
2015-12-01 14:28:01 -05:00
|
|
|
response.request = ActionDispatch::Request.empty
|
2014-09-05 16:33:20 -04:00
|
|
|
status, headers, body = *response
|
2014-02-02 17:55:35 -05:00
|
|
|
|
|
|
|
assert_equal 404, status
|
|
|
|
assert_equal({ 'Content-Type' => 'text/plain' }, headers)
|
|
|
|
assert_equal ['Not Found'], body.each.to_a
|
|
|
|
end
|
2014-02-08 20:40:08 -05:00
|
|
|
|
2015-01-02 21:25:57 -05:00
|
|
|
test "[response.to_a].flatten does not recurse infinitely" do
|
2014-02-08 20:40:08 -05:00
|
|
|
Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely
|
2015-01-02 21:25:57 -05:00
|
|
|
status, headers, body = [@response.to_a].flatten
|
2014-02-08 20:40:08 -05:00
|
|
|
assert_equal @response.status, status
|
|
|
|
assert_equal @response.headers, headers
|
|
|
|
assert_equal @response.body, body.each.to_a.join
|
|
|
|
end
|
|
|
|
end
|
2014-09-05 16:33:20 -04:00
|
|
|
|
2014-09-03 11:16:37 -04:00
|
|
|
test "compatibility with Rack::ContentLength" do
|
|
|
|
@response.body = 'Hello'
|
|
|
|
app = lambda { |env| @response.to_a }
|
|
|
|
env = Rack::MockRequest.env_for("/")
|
|
|
|
|
|
|
|
status, headers, body = app.call(env)
|
|
|
|
assert_nil headers['Content-Length']
|
|
|
|
|
|
|
|
status, headers, body = Rack::ContentLength.new(app).call(env)
|
|
|
|
assert_equal '5', headers['Content-Length']
|
|
|
|
end
|
2009-12-17 23:10:06 -05:00
|
|
|
end
|
|
|
|
|
2015-10-01 23:42:52 -04:00
|
|
|
class ResponseHeadersTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@response = ActionDispatch::Response.create
|
|
|
|
@response.set_header 'Foo', '1'
|
|
|
|
end
|
|
|
|
|
2015-10-03 22:14:37 -04:00
|
|
|
test 'has_header?' do
|
|
|
|
assert @response.has_header? 'Foo'
|
|
|
|
assert_not @response.has_header? 'foo'
|
|
|
|
assert_not @response.has_header? nil
|
2015-10-01 23:42:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'get_header' do
|
|
|
|
assert_equal '1', @response.get_header('Foo')
|
|
|
|
assert_nil @response.get_header('foo')
|
|
|
|
assert_nil @response.get_header(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'set_header' do
|
|
|
|
assert_equal '2', @response.set_header('Foo', '2')
|
2015-10-03 22:14:37 -04:00
|
|
|
assert @response.has_header?('Foo')
|
2015-10-01 23:42:52 -04:00
|
|
|
assert_equal '2', @response.get_header('Foo')
|
|
|
|
|
|
|
|
assert_nil @response.set_header('Foo', nil)
|
2015-10-03 22:14:37 -04:00
|
|
|
assert @response.has_header?('Foo')
|
2015-10-01 23:42:52 -04:00
|
|
|
assert_nil @response.get_header('Foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'delete_header' do
|
|
|
|
assert_nil @response.delete_header(nil)
|
|
|
|
|
|
|
|
assert_nil @response.delete_header('foo')
|
2015-10-03 22:14:37 -04:00
|
|
|
assert @response.has_header?('Foo')
|
2015-10-01 23:42:52 -04:00
|
|
|
|
|
|
|
assert_equal '1', @response.delete_header('Foo')
|
2015-10-03 22:14:37 -04:00
|
|
|
assert_not @response.has_header?('Foo')
|
2015-10-01 23:42:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'add_header' do
|
|
|
|
# Add a value to an existing header
|
|
|
|
assert_equal '1,2', @response.add_header('Foo', '2')
|
|
|
|
assert_equal '1,2', @response.get_header('Foo')
|
|
|
|
|
|
|
|
# Add nil to an existing header
|
|
|
|
assert_equal '1,2', @response.add_header('Foo', nil)
|
|
|
|
assert_equal '1,2', @response.get_header('Foo')
|
|
|
|
|
|
|
|
# Add nil to a nonexistent header
|
|
|
|
assert_nil @response.add_header('Bar', nil)
|
2015-10-03 22:14:37 -04:00
|
|
|
assert_not @response.has_header?('Bar')
|
2015-10-01 23:42:52 -04:00
|
|
|
assert_nil @response.get_header('Bar')
|
|
|
|
|
|
|
|
# Add a value to a nonexistent header
|
|
|
|
assert_equal '1', @response.add_header('Bar', '1')
|
2015-10-03 22:14:37 -04:00
|
|
|
assert @response.has_header?('Bar')
|
2015-10-01 23:42:52 -04:00
|
|
|
assert_equal '1', @response.get_header('Bar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-17 23:10:06 -05:00
|
|
|
class ResponseIntegrationTest < ActionDispatch::IntegrationTest
|
|
|
|
test "response cache control from railsish app" do
|
|
|
|
@app = lambda { |env|
|
|
|
|
ActionDispatch::Response.new.tap { |resp|
|
|
|
|
resp.cache_control[:public] = true
|
|
|
|
resp.etag = '123'
|
|
|
|
resp.body = 'Hello'
|
2015-12-01 14:28:01 -05:00
|
|
|
resp.request = ActionDispatch::Request.empty
|
2009-12-17 23:10:06 -05:00
|
|
|
}.to_a
|
|
|
|
}
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
assert_equal('public', @response.headers['Cache-Control'])
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers['ETag'])
|
2009-12-17 23:10:06 -05:00
|
|
|
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag)
|
2010-02-19 10:31:10 -05:00
|
|
|
assert_equal({:public => true}, @response.cache_control)
|
2009-12-17 23:10:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "response cache control from rackish app" do
|
|
|
|
@app = lambda { |env|
|
|
|
|
[200,
|
2014-11-10 00:23:31 -05:00
|
|
|
{'ETag' => 'W/"202cb962ac59075b964b07152d234b70"',
|
2009-12-23 16:06:53 -05:00
|
|
|
'Cache-Control' => 'public'}, ['Hello']]
|
2009-12-17 23:10:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
assert_equal('public', @response.headers['Cache-Control'])
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers['ETag'])
|
2009-12-17 23:10:06 -05:00
|
|
|
|
2014-11-10 00:23:31 -05:00
|
|
|
assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag)
|
2010-02-19 10:31:10 -05:00
|
|
|
assert_equal({:public => true}, @response.cache_control)
|
2009-12-17 23:10:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "response charset and content type from railsish app" do
|
|
|
|
@app = lambda { |env|
|
|
|
|
ActionDispatch::Response.new.tap { |resp|
|
|
|
|
resp.charset = 'utf-16'
|
2015-10-05 01:14:04 -04:00
|
|
|
resp.content_type = Mime[:xml]
|
2009-12-17 23:10:06 -05:00
|
|
|
resp.body = 'Hello'
|
2015-12-01 14:28:01 -05:00
|
|
|
resp.request = ActionDispatch::Request.empty
|
2009-12-17 23:10:06 -05:00
|
|
|
}.to_a
|
|
|
|
}
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert_response :success
|
|
|
|
|
2010-02-19 10:31:10 -05:00
|
|
|
assert_equal('utf-16', @response.charset)
|
2015-10-05 01:14:04 -04:00
|
|
|
assert_equal(Mime[:xml], @response.content_type)
|
2009-12-17 23:10:06 -05:00
|
|
|
|
|
|
|
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
|
|
|
|
end
|
|
|
|
|
|
|
|
test "response charset and content type from rackish app" do
|
|
|
|
@app = lambda { |env|
|
|
|
|
[200,
|
|
|
|
{'Content-Type' => 'application/xml; charset=utf-16'},
|
2009-12-23 16:06:53 -05:00
|
|
|
['Hello']]
|
2009-12-17 23:10:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert_response :success
|
|
|
|
|
2010-02-19 10:31:10 -05:00
|
|
|
assert_equal('utf-16', @response.charset)
|
2015-10-05 01:14:04 -04:00
|
|
|
assert_equal(Mime[:xml], @response.content_type)
|
2009-12-17 23:10:06 -05:00
|
|
|
|
|
|
|
assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type'])
|
|
|
|
end
|
2016-02-24 12:46:43 -05:00
|
|
|
|
|
|
|
test "we can set strong ETag by directly adding it as header" do
|
|
|
|
@response = ActionDispatch::Response.create
|
|
|
|
@response.add_header "ETag", '"202cb962ac59075b964b07152d234b70"'
|
|
|
|
|
|
|
|
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag)
|
|
|
|
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag'])
|
|
|
|
end
|
2009-04-26 11:26:53 -04:00
|
|
|
end
|