Module: HTTPX::Plugins::Stream::InstanceMethods

Defined in:
lib/httpx/plugins/stream.rb

Instance Method Summary collapse

Instance Method Details

#build_request(verb, uri, params = EMPTY_HASH, options = @options) ⇒ Object



185
186
187
188
189
# File 'lib/httpx/plugins/stream.rb', line 185

def build_request(verb, uri, params = EMPTY_HASH, options = @options)
  return super unless params[:stream]

  super(verb, uri, params, options.merge(STREAM_REQUEST_OPTIONS.merge(stream: true)))
end

#request(*args, **options) ⇒ Object

Raises:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/httpx/plugins/stream.rb', line 159

def request(*args, **options)
  if args.first.is_a?(Request)
    requests = args

    request = requests.first

    unless request.options.stream && !request.stream
      if options[:stream]
        warn "passing `stream: true` with a request obkect is not supported anymore. " \
             "You can instead build the request object with `stream :true`"
      end
      return super
    end
  else
    return super unless options[:stream]

    requests = build_requests(*args, options)

    request = requests.first
  end

  raise Error, "only 1 response at a time is supported for streaming requests" unless requests.size == 1

  @options.stream_response_class.new(request, self)
end