lib/pitchfork/stream_input.rb in pitchfork-0.12.0 vs lib/pitchfork/stream_input.rb in pitchfork-0.13.0

- old
+ new

@@ -1,6 +1,7 @@ # -*- encoding: binary -*- +# frozen_string_literal: true module Pitchfork # When processing uploads, pitchfork may expose a StreamInput object under # "rack.input" of the Rack environment when # Pitchfork::Configurator#rewindable_input is set to +false+ @@ -15,11 +16,11 @@ def initialize(socket, request) # :nodoc: @chunked = request.content_length.nil? @socket = socket @parser = request @buf = request.buf - @rbuf = '' + @rbuf = +'' @bytes_read = 0 filter_body(@rbuf, @buf) unless @buf.empty? end # :call-seq: @@ -39,11 +40,11 @@ # until the specified length is read (or it is the last chunk). # Otherwise, for uncommon "Transfer-Encoding: chunked" requests, # ios.read(length [, buffer]) will return immediately if there is # any data and only block when nothing is available (providing # IO#readpartial semantics). - def read(length = nil, rv = '') + def read(length = nil, rv = ''.b) if length if length <= @rbuf.size length < 0 and raise ArgumentError, "negative length #{length} given" rv.replace(@rbuf.slice!(0, length)) else @@ -77,19 +78,19 @@ # Returns nil if called at the end of file. # This takes zero arguments for strict Rack::Lint compatibility, # unlike IO#gets. def gets(sep = $/) if sep.nil? - read_all(rv = '') + read_all(rv = ''.b) return rv.empty? ? nil : rv end re = /\A(.*?#{Regexp.escape(sep)})/ begin - @rbuf.sub!(re, '') and return $1 + @rbuf.sub!(re, ''.b) and return $1 return @rbuf.empty? ? nil : @rbuf.slice!(0, @rbuf.size) if eof? @socket.readpartial(@@io_chunk_size, @buf) or eof! - filter_body(once = '', @buf) + filter_body(once = ''.b, @buf) @rbuf << once end while true end # :call-seq: