lib/httpx/parser/http1.rb in httpx-0.11.3 vs lib/httpx/parser/http1.rb in httpx-0.12.0

- old
+ new

@@ -64,19 +64,19 @@ @http_version = version.split(".").map(&:to_i) @status_code = code.to_i raise(Error, "wrong status code (#{@status_code})") unless (100..599).cover?(@status_code) - # @buffer.slice!(0, idx + 1) @buffer = @buffer.byteslice((idx + 1)..-1) nextstate(:headers) end def parse_headers headers = @headers while (idx = @buffer.index("\n")) - line = @buffer.slice!(0, idx + 1).sub(/\s+\z/, "") + line = @buffer.byteslice(0..idx).sub(/\s+\z/, "") + @buffer = @buffer.byteslice((idx + 1)..-1) if line.empty? case @state when :headers prepare_data(headers) @observer.on_headers(headers) @@ -94,14 +94,14 @@ return end separator_index = line.index(":") raise Error, "wrong header format" unless separator_index - key = line[0..separator_index - 1] + key = line.byteslice(0..(separator_index - 1)) raise Error, "wrong header format" if key.start_with?("\s", "\t") key.strip! - value = line[separator_index + 1..-1] + value = line.byteslice((separator_index + 1)..-1) value.strip! raise Error, "wrong header format" if value.nil? (headers[key.downcase] ||= []) << value end