Skip to content

Commit 4ce1581

Browse files
author
nahi
committed
* lib/webrick/httpresponse.rb (HTTPResponse#setup_header): Close
HTTP/1.1 connection when returning an IO object as response body without setting HTTPResponse#chunked to true. See #855 no.1. * test/webrick/test_httpserver.rb: Test it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 908baef commit 4ce1581

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Tue Jun 21 21:50:37 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
2+
3+
* lib/webrick/httpresponse.rb (HTTPResponse#setup_header): Close
4+
HTTP/1.1 connection when returning an IO object as response body
5+
without setting HTTPResponse#chunked to true. See #855 no.1.
6+
7+
* test/webrick/test_httpserver.rb: Test it.
8+
19
Tue Jun 21 21:27:34 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
210

311
* internal.h: move rb_thread_io_blocking_region() declaration

lib/webrick/httpresponse.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def setup_header()
204204
elsif keep_alive?
205205
if chunked? || @header['content-length']
206206
@header['connection'] = "Keep-Alive"
207+
else
208+
msg = "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"
209+
@logger.warn(msg)
210+
@header['connection'] = "close"
211+
@keep_alive = false
207212
end
208213
else
209214
@header['connection'] = "close"

test/webrick/test_httpserver.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,33 @@ def test_callbacks
258258
assert_equal(stopped, 1)
259259
end
260260

261+
def test_response_io_without_chunked_set
262+
config = {
263+
:ServerName => "localhost"
264+
}
265+
TestWEBrick.start_httpserver(config){|server, addr, port, log|
266+
server.mount_proc("/", lambda { |req, res|
267+
r,w = IO.pipe
268+
# Test for not setting chunked...
269+
# res.chunked = true
270+
res.body = r
271+
w << "foo"
272+
w.close
273+
})
274+
Thread.pass while server.status != :Running
275+
http = Net::HTTP.new(addr, port)
276+
req = Net::HTTP::Get.new("/")
277+
req['Connection'] = 'Keep-Alive'
278+
begin
279+
timeout(2) do
280+
http.request(req){|res| assert_equal("foo", res.body) }
281+
end
282+
rescue Timeout::Error
283+
flunk('corrupted reponse')
284+
end
285+
}
286+
end
287+
261288
def test_request_handler_callback_is_deprecated
262289
requested = 0
263290
config = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy