Permalink
Browse files

fixes for content_length calculation under 1.8.7

closes #116
closes #121
  • Loading branch information...
1 parent 92a8e6b commit b528cec18342f281aa6d38d3539a504fbe52170c @geemus geemus committed Apr 12, 2012
Showing with 18 additions and 1 deletion.
  1. +5 −1 lib/excon/connection.rb
  2. +1 −0 tests/data/xs
  3. +12 −0 tests/test_helper.rb
View
@@ -155,7 +155,11 @@ def detect_content_length(body)
# IO object: File, Tempfile, etc.
body.size
else
- 0
+ begin
+ File.size(body) # for 1.8.7 where file does not have size
+ rescue
+ 0
+ end
end
end
View
@@ -0,0 +1 @@
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
View
@@ -77,6 +77,12 @@ def basic_tests(url = 'http://127.0.0.1:9292')
tests('POST /echo') do
+ tests('with file').returns('x' * 100 + "\n") do
+ file_path = File.join(File.dirname(__FILE__), "data", "xs")
+ response = connection.request(:method => :post, :path => '/echo', :body => File.open(file_path))
+ response.body
+ end
+
tests('without request_block').returns('x' * 100) do
response = connection.request(:method => :post, :path => '/echo', :body => 'x' * 100)
response.body
@@ -95,6 +101,12 @@ def basic_tests(url = 'http://127.0.0.1:9292')
tests('PUT /echo') do
+ tests('with file').returns('x' * 100 + "\n") do
+ file_path = File.join(File.dirname(__FILE__), "data", "xs")
+ response = connection.request(:method => :put, :path => '/echo', :body => File.open(file_path))
+ response.body
+ end
+
tests('without request_block').returns('x' * 100) do
response = connection.request(:method => :put, :path => '/echo', :body => 'x' * 100)
response.body

0 comments on commit b528cec

Please sign in to comment.