diff options
author | Eric Wong <e@80x24.org> | 2016-01-04 11:41:30 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-01-04 11:41:30 +0000 |
commit | e502a8e21e597895ccb6508b35af1d975c33aeb0 (patch) | |
tree | e69f6be27aae51a93773710e09f432736769a16c /lib/yahns/http_context.rb | |
parent | 6ea85b061e650cfe348ece306a13d568559fb844 (diff) | |
download | yahns-e502a8e21e597895ccb6508b35af1d975c33aeb0.tar.gz |
Apparently, StringIO#binmode has been totally broken in 1.9+ and I've always hidden this bug with the combination of an explicit string and magic "encoding: binary" comments :x ref: https://bugs.ruby-lang.org/issues/11945
Diffstat (limited to 'lib/yahns/http_context.rb')
-rw-r--r-- | lib/yahns/http_context.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb index c7258ad..10be062 100644 --- a/lib/yahns/http_context.rb +++ b/lib/yahns/http_context.rb @@ -80,13 +80,16 @@ module Yahns::HttpContext # :nodoc: def tmpio_for(len, env) # short requests are most common - return StringIO.new.binmode if len && len <= @client_body_buffer_size; - - # too big or chunked, unknown length - tmp = @input_buffer_tmpdir - mbs = @client_max_body_size - tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp) - (env['rack.tempfiles'] ||= []) << tmp + if len && len <= @client_body_buffer_size; + # Can't use binmode, yet: https://bugs.ruby-lang.org/issues/11945 + tmp = StringIO.new + tmp.set_encoding(Encoding::ASCII_8BIT) + else # too big or chunked, unknown length + tmp = @input_buffer_tmpdir + mbs = @client_max_body_size + tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp) + (env['rack.tempfiles'] ||= []) << tmp + end tmp end end |