8000 * lib/net/http/generic_request.rb (Net::HTTPGenericRequest): · ruby/net-http@8b561ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b561ed

Browse files
committed
* lib/net/http/generic_request.rb (Net::HTTPGenericRequest):
set content-length to zero on empty post requests by Gregory Ostermayr <gregory.ostermayr@gmail.com> ruby/ruby#201 fix GH-201 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 99f37e8 commit 8b561ed

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/net/http/generic_request.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def body_stream=(input)
8989
def set_body_internal(str) #:nodoc: internal use only
9090
raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream)
9191
self.body = str if str
92+
if @body.nil? && @body_stream.nil? && @body_data.nil? && request_body_permitted?
93+
self.body = ''
94+
end
9295
end
9396

9497
#

test/net/http/test_http.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def test_post
310310
start {|http|
311311
_test_post__base http
312312
_test_post__file http
313+
_test_post__no_data http
313314
}
314315
end
315316

@@ -332,6 +333,14 @@ def _test_post__file(http)
332333
assert_equal data, f.string
333334
end
334335

336+
def _test_post__no_data(http)
337+
unless self.is_a?(TestNetHTTP_v1_2_chunked)
338+
data = nil
339+
res = http.post('/', data)
340+
assert_not_equal '411', res.code
341+
end
342+
end
343+
335344
def test_s_post_form
336345
url = "http://#{config('host')}:#{config('port')}/"
337346
res = Net::HTTP.post_form(

0 commit comments

Comments
 (0)
0