Skip to content

Net::HTTPResponse has bad nil handling in read_body and stream_check #70

Closed
@BrianHawley

Description

@BrianHawley

I was getting a weird error from Net::HTTPResponse, and noticed that a couple methods had some bad nil checking.

In read_body, it sets @body = nil and then later on calls string methods on it like @body.force_encoding. Right after you set @read = true you should add this code: return if @body.nil?.

Then, the weird error was from stream_check:

undefined method `closed?' for nil:NilClass (NoMethodError)

    raise IOError, 'attempt to read body out of block' if @socket.closed?

Since you set @socket = nil in reading_body, the stream_check method should be:

def stream_check
  raise IOError, 'attempt to read body out of block' if @socket.nil? || @socket.closed?
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions