mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-10 00:03:15 -04:00
fix request headers in Adapter::Rack
This commit is contained in:
parent
96ba8eb2d7
commit
2ced228f71
@ -26,6 +26,9 @@ module Faraday
|
||||
SystemTimer = Timeout unless defined? ::SystemTimer
|
||||
end
|
||||
|
||||
# not prefixed with "HTTP_"
|
||||
SPECIAL_HEADERS = %w[ CONTENT_LENGTH CONTENT_TYPE ]
|
||||
|
||||
def initialize(faraday_app, rack_app)
|
||||
super(faraday_app)
|
||||
mock_session = ::Rack::MockSession.new(rack_app)
|
||||
@ -39,11 +42,11 @@ module Faraday
|
||||
:input => env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
||||
}
|
||||
|
||||
if env[:request_headers]
|
||||
env[:request_headers].each do |k,v|
|
||||
rack_env[k.upcase.gsub('-', '_')] = v
|
||||
end
|
||||
end
|
||||
env[:request_headers].each do |name, value|
|
||||
name = name.upcase.tr('-', '_')
|
||||
name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name
|
||||
rack_env[name] = value
|
||||
end if env[:request_headers]
|
||||
|
||||
timeout = env[:request][:timeout] || env[:request][:open_timeout]
|
||||
response = if timeout
|
||||
|
@ -10,22 +10,16 @@ module Adapters
|
||||
[FaradayTestServer]
|
||||
end
|
||||
|
||||
Integration.apply(self, :NonParallel) do
|
||||
# TODO: find out why
|
||||
undef :test_GET_sends_user_agent
|
||||
# no Integration.apply because this doesn't require a server as a separate process
|
||||
include Integration::Common
|
||||
include Integration::NonParallel
|
||||
|
||||
# not using original test because error is swallowed by sinatra
|
||||
def test_timeout
|
||||
conn = create_connection(:request => {:timeout => 1, :open_timeout => 1})
|
||||
begin
|
||||
res = conn.get '/slow'
|
||||
rescue Faraday::Error::ClientError => e
|
||||
assert_equal 500, e.response[:status]
|
||||
assert e.response[:body] =~ /Faraday::Error::Timeout/
|
||||
return true
|
||||
end
|
||||
assert false, "did not timeout"
|
||||
end
|
||||
# not using shared test because error is swallowed by Sinatra
|
||||
def test_timeout
|
||||
conn = create_connection(:request => {:timeout => 1, :open_timeout => 1})
|
||||
err = assert_raise(Faraday::Error::ClientError) { conn.get '/slow' }
|
||||
assert_equal 500, err.response[:status]
|
||||
assert err.response[:body] =~ /Faraday::Error::Timeout/
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user