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

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

Instance Method Summary collapse

Instance Method Details

#build_requestObject



43
44
45
46
47
# File 'lib/httpx/plugins/cookies.rb', line 43

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

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



26
27
28
# File 'lib/httpx/plugins/cookies.rb', line 26

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

#wrapObject



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

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