Skip to content

Commit 89a4ac2

Browse files
committed
Merge branch 'master' of github.com:oauth/oauth-ruby
2 parents 7665863 + f565250 commit 89a4ac2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/oauth/consumer.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ def create_http(_url = nil)
317317
else
318318
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
319319
end
320+
321+
http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 30
322+
http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout]
323+
320324
http_object
321325
end
322326

@@ -330,7 +334,7 @@ def create_http_request(http_method, path, *arguments)
330334

331335
# if the base site contains a path, add it now
332336
uri = URI.parse(site)
333-
path = uri.path + path if uri.path
337+
path = uri.path + path if uri.path && uri.path != '/'
334338

335339
headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
336340

@@ -352,9 +356,8 @@ def create_http_request(http_method, path, *arguments)
352356
end
353357

354358
if data.is_a?(Hash)
355-
form_data = {}
356-
data.each {|k,v| form_data[k.to_s] = v if !v.nil?}
357-
request.set_form_data(form_data)
359+
request.body = OAuth::Helper.normalize(data)
360+
request.content_type = 'application/x-www-form-urlencoded'
358361
elsif data
359362
if data.respond_to?(:read)
360363
request.body_stream = data

test/test_consumer.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ def test_site_with_path
8989
@consumer.request(:get, '/people', nil, {})
9090
end
9191

92+
def test_post_of_nested_params_maintains_nesting
93+
@consumer=OAuth::Consumer.new(
94+
"key",
95+
"secret",
96+
{
97+
:site=>"http://twitter.com"
98+
})
99+
request = @consumer.create_signed_request(
100+
:post,
101+
'/people',
102+
nil,
103+
{},
104+
{
105+
:key => {
106+
:subkey => 'value'
107+
}
108+
})
109+
assert_equal 'key%5Bsubkey%5D=value', request.body
110+
assert_equal request.content_type, 'application/x-www-form-urlencoded'
111+
end
112+
92113
def test_override_paths
93114
@consumer=OAuth::Consumer.new(
94115
"key",

0 commit comments

Comments
 (0)