mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Http::Headers respects headers that are not prefixed with HTTP_
This commit is contained in:
parent
b5493c83f5
commit
8945be464f
3 changed files with 30 additions and 7 deletions
|
@ -1,5 +1,9 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## Rails 4.0.0 (unreleased) ##
|
||||||
|
|
||||||
|
* Http::Headers respects headers that are not prefixed with HTTP_
|
||||||
|
|
||||||
|
*Yves Senn*
|
||||||
|
|
||||||
* Fix incorrectly appended square brackets to a multiple select box
|
* Fix incorrectly appended square brackets to a multiple select box
|
||||||
if an explicit name has been given and it already ends with "[]"
|
if an explicit name has been given and it already ends with "[]"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
module ActionDispatch
|
module ActionDispatch
|
||||||
module Http
|
module Http
|
||||||
class Headers
|
class Headers
|
||||||
|
NON_PREFIX_VARIABLES = %w(
|
||||||
|
CONTENT_TYPE CONTENT_LENGTH
|
||||||
|
HTTPS AUTH_TYPE GATEWAY_INTERFACE
|
||||||
|
PATH_INFO PATH_TRANSLATED QUERY_STRING
|
||||||
|
REMOTE_ADDR REMOTE_HOST REMOTE_IDENT REMOTE_USER
|
||||||
|
REQUEST_METHOD SCRIPT_NAME
|
||||||
|
SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE
|
||||||
|
)
|
||||||
|
HEADER_REGEXP = /\A[A-Za-z-]+\z/
|
||||||
|
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def initialize(env = {})
|
def initialize(env = {})
|
||||||
|
@ -32,7 +42,9 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def cgi_name(k)
|
def cgi_name(k)
|
||||||
"HTTP_#{k.upcase.gsub(/-/, '_')}"
|
k = k.upcase.gsub(/-/, '_')
|
||||||
|
k = "HTTP_#{k.upcase.gsub(/-/, '_')}" unless NON_PREFIX_VARIABLES.include?(k)
|
||||||
|
k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,14 +3,16 @@ require 'abstract_unit'
|
||||||
class HeaderTest < ActiveSupport::TestCase
|
class HeaderTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
@headers = ActionDispatch::Http::Headers.new(
|
@headers = ActionDispatch::Http::Headers.new(
|
||||||
"HTTP_CONTENT_TYPE" => "text/plain"
|
"CONTENT_TYPE" => "text/plain",
|
||||||
|
"HTTP_REFERER" => "/some/page"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_each
|
def test_each
|
||||||
headers = []
|
headers = []
|
||||||
@headers.each { |pair| headers << pair }
|
@headers.each { |pair| headers << pair }
|
||||||
assert_equal [["HTTP_CONTENT_TYPE", "text/plain"]], headers
|
assert_equal [["CONTENT_TYPE", "text/plain"],
|
||||||
|
["HTTP_REFERER", "/some/page"]], headers
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_setter
|
def test_setter
|
||||||
|
@ -19,19 +21,24 @@ class HeaderTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_key?
|
def test_key?
|
||||||
assert @headers.key?('HTTP_CONTENT_TYPE')
|
assert @headers.key?('CONTENT_TYPE')
|
||||||
assert @headers.include?('HTTP_CONTENT_TYPE')
|
assert @headers.include?('CONTENT_TYPE')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fetch_with_block
|
def test_fetch_with_block
|
||||||
assert_equal 'omg', @headers.fetch('notthere') { 'omg' }
|
assert_equal 'omg', @headers.fetch('notthere') { 'omg' }
|
||||||
end
|
end
|
||||||
|
|
||||||
test "content type" do
|
test "accessing http header" do
|
||||||
|
assert_equal "/some/page", @headers["Referer"]
|
||||||
|
assert_equal "/some/page", @headers["referer"]
|
||||||
|
assert_equal "/some/page", @headers["HTTP_REFERER"]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "accessing special header" do
|
||||||
assert_equal "text/plain", @headers["Content-Type"]
|
assert_equal "text/plain", @headers["Content-Type"]
|
||||||
assert_equal "text/plain", @headers["content-type"]
|
assert_equal "text/plain", @headers["content-type"]
|
||||||
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
||||||
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fetch" do
|
test "fetch" do
|
||||||
|
|
Loading…
Reference in a new issue