WEBrick SSL output size limit?

Greetings, dear sirs!

I am developing a tiny server software that provides the clients with
certain XML documents via HTTPS. I am using WEBrick applet for this in
the following way:

def do_GET(req, res)
company_id = do_auth(req, res)
res.body = get_the_xml_body(company_id)
res[‘Content-Type’] = “text/xml”
res[‘X-Company-Id’] = company_id
res.keep_alive = false
puts “All internal request processing is finished. Body length
#{res.body.length}, size #{res.body.size}, byte size

Everything works fine until the document size exceeds 16k. When this
happens, the client gets only 16383 bytes of the XML. WEBrick log is the

[2009-07-02 13:10:06] INFO DirectPagerServer#start: pid=22528 port=2000
All internal request processing is finished. Body length 15612, size
15612, byte size 17496
::ffff: - user [02/Jul/2009:13:10:18 MSD] “GET
/data/?nowait=1 HTTP/1.1” 200 17496

It seems that everything in WEBrick goes fine until the data hits
SSLSocket, which is used to transfer all the data to the client. At this
point it gets cut. I’ve tried setting “res.keep_alive = true”, this
makes the client hit timeout, since it never gets all the promised 17496
bytes of data thus having no reason to finish the connection.

I’ve heard of SSL message limitation of 16k. So I’ve tried setting
WEBrick buffer size to something lower:

WEBrick::Config::HTTP[:InputBufferSize] =
WEBrick::Config::HTTP[:OutputBufferSize] = 1024

And then turning on chunked with “res.chunked = true” to force WEBrick
buffer usage. This eliminated hangup problem even with keep_alive on,
but produces garbled documents in the end.

Has anybody faced this problem? Any ideas?

Thank you in advance!