Skip to content

set content-length to zero on empty post requests #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/net/http/generic_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def body_stream=(input)
def set_body_internal(str) #:nodoc: internal use only
raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream)
self.body = str if str
if @body.nil? && @body_stream.nil? && @body_data.nil? && request_body_permitted?
self.body = ''
end
end

#
Expand Down
9 changes: 9 additions & 0 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def test_post
start {|http|
_test_post__base http
_test_post__file http
_test_post__no_data http
}
end

Expand All @@ -333,6 +334,14 @@ def _test_post__file(http)
assert_equal data, f.string
end

def _test_post__no_data(http)
unless self.is_a?(TestNetHTTP_v1_2_chunked)
data = nil
res = http.post('/', data)
assert_not_equal '411', res.code
end
end

def test_s_post_form
url = "http://#{config('host')}:#{config('port')}/"
res = Net::HTTP.post_form(
Expand Down