Class: HTTP::Session::Client

Inherits:
Object
  • Object
show all
Includes:
Perform
Defined in:
lib/http/session/client.rb,
lib/http/session/client/perform.rb

Defined Under Namespace

Modules: Perform

Constant Summary

Constants included from Perform

Perform::HTTP_OR_HTTPS_RE

Instance Attribute Summary

Attributes included from Perform

#default_options

Instance Method Summary collapse

Methods included from Perform

#httprb_initialize, #httprb_perform

Constructor Details

#initialize(default_options, session) ⇒ Client

Returns a new instance of Client.

Parameters:

  • default_options (Hash)
  • session (Session)


7
8
9
10
# File 'lib/http/session/client.rb', line 7

def initialize(default_options, session)
  httprb_initialize(default_options)
  @session = session
end

Instance Method Details

#request(verb, uri, opts) ⇒ Response

Parameters:

  • verb
  • uri
  • opts (Hash)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/http/session/client.rb', line 16

def request(verb, uri, opts)
  data = @session.make_http_request_data
  hist = []

  opts = @default_options.merge(opts)
  opts = _hs_handle_http_request_options_cookies(opts, data[:cookies])
  opts = _hs_handle_http_request_options_follow(opts, hist)

  req = build_request(verb, uri, opts)
  res = perform(req, opts)
  return res unless opts.follow

  HTTP::Redirector.new(opts.follow).perform(req, res) do |request|
    request = HTTP::Session::Request.new(request)
    perform(request, opts)
  end.tap do |res|
    res.history = hist
  end
end