Skip to content

Commit

Permalink
Appease some proxies by always including a Content-Length with all re…
Browse files Browse the repository at this point in the history
…quests.
  • Loading branch information
marcel committed Jun 7, 2008
1 parent d6cd815 commit d0a3ed6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
trunk:

- Bug #13052 fixed. Appease some proxies by always including a Content-Length with all requests. Reported by [James Murty (jmurty)]

- Bug #13756 fixed. Attributes that are false should not raise NoMethodError in Base#method_missing. Fixed by [Scott Patten]

- Bug #19189 fixed. No longer reference Date::ABBR_MONTHS constant which was removed in Ruby 1.8.6. Reported by [Khurram Virani (kvirani)]
Expand Down
8 changes: 5 additions & 3 deletions lib/aws/s3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def request(verb, path, headers = {}, body = nil, attempts = 0, &block)
authenticate!(request)
if body
if body.respond_to?(:read)
request.body_stream = body
request.content_length = body.respond_to?(:lstat) ? body.lstat.size : body.size
request.body_stream = body
else
request.body = body
end
end
request.content_length = body.respond_to?(:lstat) ? body.lstat.size : body.size
else
request.content_length = 0
end
http.request(request, &block)
end
Expand Down
10 changes: 9 additions & 1 deletion test/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_connecting_through_a_proxy
end

def test_request_only_escapes_the_path_the_first_time_it_runs_and_not_subsequent_times
connection = Connection.new(@keys)
connection = Connection.new(@keys)
unescaped_path = 'path with spaces'
escaped_path = 'path%20with%20spaces'

Expand All @@ -115,6 +115,14 @@ def test_request_only_escapes_the_path_the_first_time_it_runs_and_not_subsequent
flexmock(connection.http).should_receive(:request).ordered
connection.request :put, unescaped_path
end

def test_if_request_has_no_body_then_the_content_length_is_set_to_zero
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=13052&group_id=2409&atid=9356
connection = Connection.new(@keys)
flexmock(Net::HTTP::Put).new_instances.should_receive(:content_length=).once.with(0).ordered
flexmock(connection.http).should_receive(:request).once.ordered
connection.request :put, 'path does not matter'
end
end

class ConnectionOptionsTest < Test::Unit::TestCase
Expand Down

0 comments on commit d0a3ed6

Please sign in to comment.