Module: HTTPX::Plugins::Cookies::InstanceMethods

Extended by:
Forwardable
Defined in:
lib/httpx/plugins/cookies.rb

Instance Method Summary collapse

Instance Method Details

#build_requestObject



41
42
43
44
45
# File 'lib/httpx/plugins/cookies.rb', line 41

def build_request(*)
  request = super
  request.headers.set_cookie(request.options.cookies[request.uri])
  request
end

#initialize(options = {}, &blk) ⇒ Object



24
25
26
# File 'lib/httpx/plugins/cookies.rb', line 24

def initialize(options = {}, &blk)
  super({ cookies: Jar.new }.merge(options), &blk)
end

#make_jar(*args) ⇒ Object

factory method to return a Jar to the user, which can then manipulate externally to the session.



49
50
51
# File 'lib/httpx/plugins/cookies.rb', line 49

def make_jar(*args)
  Jar.new(*args)
end

#wrapObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/httpx/plugins/cookies.rb', line 28

def wrap
  return super unless block_given?

  super do |session|
    old_cookies_jar = @options.cookies.dup
    begin
      yield session
    ensure
      @options = @options.merge(cookies: old_cookies_jar)
    end
  end
end