File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,8 @@ def setup_raw_request
245245 if body . multipart?
246246 content_type = "multipart/form-data; boundary=#{ body . boundary } "
247247 @raw_request [ 'Content-Type' ] = content_type
248+ elsif options [ :body ] . respond_to? ( :to_hash ) && !@raw_request [ 'Content-Type' ]
249+ @raw_request [ 'Content-Type' ] = 'application/x-www-form-urlencoded'
248250 end
249251 @raw_request . body = body . call
250252 end
Original file line number Diff line number Diff line change 378378 end
379379 end
380380 end
381+
382+ context "when body is a Hash" do
383+ subject ( :headers ) do
384+ @request . send ( :setup_raw_request )
385+ headers = @request . instance_variable_get ( :@raw_request ) . each_header . to_a
386+ Hash [ *headers . flatten ]
387+ end
388+
389+ it "sets header Content-Type: application/x-www-form-urlencoded" do
390+ @request . options [ :body ] = { foo : 'bar' }
391+
392+ expect ( headers [ 'content-type' ] ) . to eq ( 'application/x-www-form-urlencoded' )
393+ end
394+
395+ context "and header Content-Type is provided" do
396+ it "does not overwrite the provided Content-Type" do
397+ @request . options [ :body ] = { foo : 'bar' }
398+ @request . options [ :headers ] = { 'Content-Type' => 'application/json' }
399+
400+ expect ( headers [ 'content-type' ] ) . to eq ( 'application/json' )
401+ end
402+ end
403+ end
381404 end
382405
383406 describe 'http' do
You can’t perform that action at this time.
0 commit comments