Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reference HTTP_VERSION internally #969

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rack/chunked.rb
Expand Up @@ -43,7 +43,7 @@ def initialize(app)
# a version (nor response headers)
def chunkable_version?(ver)
case ver
when "HTTP/1.0", nil, "HTTP/0.9"
when 'HTTP/1.0', nil, 'HTTP/0.9'
false
else
true
Expand All @@ -54,7 +54,7 @@ def call(env)
status, headers, body = @app.call(env)
headers = HeaderHash.new(headers)

if ! chunkable_version?(env[HTTP_VERSION]) ||
if ! chunkable_version?(env[SERVER_PROTOCOL]) ||
STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
headers[CONTENT_LENGTH] ||
headers[TRANSFER_ENCODING]
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/common_logger.rb
Expand Up @@ -49,7 +49,7 @@ def log(env, status, header, began_at)
env[REQUEST_METHOD],
env[PATH_INFO],
env[QUERY_STRING].empty? ? "" : "?"+env[QUERY_STRING],
env[HTTP_VERSION],
env[SERVER_PROTOCOL],
status.to_s[0..3],
length,
now - began_at ]
Expand Down
8 changes: 4 additions & 4 deletions test/spec_chunked.rb
Expand Up @@ -16,7 +16,7 @@ def chunked(app)

before do
@env = Rack::MockRequest.
env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET')
env_for('/', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET')
end

it 'chunk responses with no Content-Length' do
Expand Down Expand Up @@ -59,7 +59,7 @@ def chunked(app)

it 'not modify response when client is HTTP/1.0' do
app = lambda { |env| [200, {"Content-Type" => "text/plain"}, ['Hello', ' ', 'World!']] }
@env['HTTP_VERSION'] = 'HTTP/1.0'
@env['SERVER_PROTOCOL'] = 'HTTP/1.0'
status, headers, body = chunked(app).call(@env)
status.must_equal 200
headers.wont_include 'Transfer-Encoding'
Expand All @@ -75,10 +75,10 @@ def chunked(app)
body.join.must_equal 'Hello World!'
end

@env.delete('HTTP_VERSION') # unicorn will do this on pre-HTTP/1.0 requests
@env.delete('SERVER_PROTOCOL') # unicorn will do this on pre-HTTP/1.0 requests
check.call

@env['HTTP_VERSION'] = 'HTTP/0.9' # not sure if this happens in practice
@env['SERVER_PROTOCOL'] = 'HTTP/0.9' # not sure if this happens in practice
check.call
end

Expand Down