lib/protocol/http1/body/chunked.rb in protocol-http1-0.24.0 vs lib/protocol/http1/body/chunked.rb in protocol-http1-0.25.0

- old
+ new

@@ -20,27 +20,31 @@ @length = 0 @count = 0 end + attr :count + + def length + # We only know the length once we've read everything. This is because the length is not known until the final chunk is read. + if @finished + @length + end + end + def empty? @connection.nil? end - def discard + def close(error = nil) if connection = @connection @connection = nil - # We only close the connection if we haven't completed reading the entire body: unless @finished connection.close_read end end - end - - def close(error = nil) - self.discard super end VALID_CHUNK_LENGTH = /\A[0-9a-fA-F]+\z/ @@ -80,10 +84,11 @@ @count += 1 return chunk else # The connection has been closed before we have read the requested length: - self.discard + @connection.close_read + @connection = nil end end # If the connection has been closed before we have read the final chunk, raise an error: raise EOFError, "connection closed before expected length was read!"