Method: Down::Http#open

Defined in:
lib/down/http.rb

#open(url, rewindable: true, **options, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/down/http.rb', line 60

def open(url, rewindable: true, **options, &block)
  response = get(url, **options, &block)

  response_error!(response) unless response.status.success?

  Down::ChunkedIO.new(
    chunks:     enum_for(:stream_body, response),
    size:       response.content_length,
    encoding:   response.content_type.charset,
    rewindable: rewindable,
    on_close:   (-> { response.connection.close } unless default_client.persistent?),
    data:       { status: response.code, headers: response.headers.to_h, response: response },
  )
end