Skip to content

Commit ee5d576

Browse files
committed
don't stomp on request body
* store request_body in env * allow response to contain all the information of the request
1 parent cc9772b commit ee5d576

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/faraday/adapter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def call(env)
3535
end
3636

3737
def save_response(env, status, body, headers = nil)
38-
env.status = status
39-
env.body = body
38+
env.status = status
39+
env.request_body = env.body
40+
env.body = body
4041
env.response_headers = Utils::Headers.new.tap do |response_headers|
4142
response_headers.update headers unless headers.nil?
4243
yield(response_headers) if block_given?

lib/faraday/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def new_builder(block)
252252
end
253253

254254
class Env < Options.new(:method, :body, :url, :request, :request_headers,
255-
:ssl, :parallel_manager, :params, :response, :response_headers, :status)
255+
:ssl, :parallel_manager, :params, :response, :response_headers, :status, :request_body)
256256

257257
ContentLength = 'Content-Length'.freeze
258258
StatusesWithoutBody = Set.new [204, 304]

test/adapters/integration.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ def test_POST_sends_files
134134
assert_equal "file integration.rb text/x-ruby #{File.size(__FILE__)}", resp.body
135135
end
136136

137+
def test_save_request_body
138+
resp = post('echo') { |req| req.body = {"mah" => "body"} }
139+
140+
assert_equal 'post {"mah"=>"body"}', resp.body
141+
end
142+
137143
def test_PUT_send_url_encoded_params
138144
assert_equal %(put {"name"=>"zack"}), put('echo', :name => 'zack').body
139145
end

0 commit comments

Comments
 (0)