diff options
author | Eric Wong <e@80x24.org> | 2016-01-02 22:29:12 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-01-02 22:29:28 +0000 |
commit | 9e24bae3428f726800da2963a8f2695f7d4064cd (patch) | |
tree | dd4ce29efffa4f0da9c6d9ada903a277ec81196b /lib/yahns/max_body/wrapper.rb | |
parent | 1105a6957eed26a922a27bd6e6dbbc457524b664 (diff) | |
download | yahns-9e24bae3428f726800da2963a8f2695f7d4064cd.tar.gz |
There are likely yet-to-be-discovered bugs in here. Also, keeping explicit #freeze calls for 2.2 users, since most users have not migrated to 2.3, yet.
Diffstat (limited to 'lib/yahns/max_body/wrapper.rb')
-rw-r--r-- | lib/yahns/max_body/wrapper.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/yahns/max_body/wrapper.rb b/lib/yahns/max_body/wrapper.rb index e618568..b8ed8a6 100644 --- a/lib/yahns/max_body/wrapper.rb +++ b/lib/yahns/max_body/wrapper.rb @@ -1,11 +1,14 @@ # -*- encoding: binary -*- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net> # License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt) +# frozen_string_literal: true # # This is only used for chunked request bodies, which are rare class Yahns::MaxBody::Wrapper # :nodoc: def initialize(rack_input, limit) - @input, @limit, @rbuf = rack_input, limit, '' + @input = rack_input + @limit = limit + @rbuf = ''.dup end def each @@ -16,7 +19,7 @@ class Yahns::MaxBody::Wrapper # :nodoc: # chunked encoding means this method behaves more like readpartial, # since Rack does not support a method named "readpartial" - def read(length = nil, rv = '') + def read(length = nil, rv = ''.dup) if length if length <= @rbuf.size length < 0 and raise ArgumentError, "negative length #{length} given" @@ -53,7 +56,7 @@ class Yahns::MaxBody::Wrapper # :nodoc: end while true end - def checked_read(length = 16384, buf = '') + def checked_read(length = 16384, buf = ''.dup) if @input.read(length, buf) throw :yahns_EFBIG if ((@limit -= buf.size) < 0) return buf @@ -62,7 +65,7 @@ class Yahns::MaxBody::Wrapper # :nodoc: def read_all rv = @rbuf.slice!(0, @rbuf.size) - tmp = '' + tmp = ''.dup while checked_read(16384, tmp) rv << tmp end |