Class: RestClient::Request

Inherits:
Object
  • Object
show all
Includes:
Curlyrest
Defined in:
lib/curlyrest.rb

Overview

restClient request class

Constant Summary

Constants included from Curlyrest

Curlyrest::VERSION

Instance Method Summary collapse

Methods included from Curlyrest

#curl_transmit

Instance Method Details

#curl_execute(&block) ⇒ Object



176
177
178
179
180
181
182
183
184
185
# File 'lib/curlyrest.rb', line 176

def curl_execute(& block)
  h = if processed_headers['No-Restclient-Headers'] == true
        headers
      else
        processed_headers
      end
  r = curl_transmit(uri, method, h, payload,
                    timeout: open_timeout, &block)
  RestClient::Response.create(r.body, r, self)
end

#execute(&block) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/curlyrest.rb', line 162

def execute(& block)
  # With 2.0.0+, net/http accepts URI objects in requests and handles
  # wrapping IPv6 addresses in [] for use in the Host request header.
  if processed_headers['Use-Curl'] || ENV['FORCE_CURL_DEBUG']
    curl_execute(& block)
  else
    transmit(uri, net_http_request_class(method)
                    .new(uri, processed_headers),
             payload, & block)
  end
ensure
  payload&.close
end


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/curlyrest.rb', line 187

def process_cookie_args!(uri, headers, args)

  # Avoid ambiguity in whether options from headers or options from
  # Request#initialize should take precedence by raising ArgumentError when
  # both are present. Prior versions of rest-client claimed to give
  # precedence to init options, but actually gave precedence to headers.
  # Avoid that mess by erroring out instead.
  if headers[:cookies] && args[:cookies]
    raise ArgumentError.new(
      "Cannot pass :cookies in Request.new() and in headers hash")
  end

  cookies_data = headers.delete(:cookies) || args[:cookies]

  # this method has problems if no cookies are in the request
  return if cookies_data.nil?

  # return copy of cookie jar as is
  if cookies_data.is_a?(HTTP::CookieJar)
    return cookies_data.dup
  end

  # convert cookies hash into a CookieJar
  jar = HTTP::CookieJar.new

  (cookies_data || []).each do |key, val|

    # Support for Array<HTTP::Cookie> mode:
    # If key is a cookie object, add it to the jar directly and assert that
    # there is no separate val.
    if key.is_a?(HTTP::Cookie)
      if val
        raise ArgumentError.new("extra cookie val: #{val.inspect}")
      end

      jar.add(key)
      next
    end

    if key.is_a?(Symbol)
      key = key.to_s
    end

    # assume implicit domain from the request URI, and set for_domain to
    # permit subdomains
    jar.add(HTTP::Cookie.new(key, val, domain: uri.hostname.downcase,
                             path: '/', for_domain: true))
  end

  jar
end