Commit 24ff45d2 authored by Tiago's avatar Tiago
Browse files

cookies: add #make_jar to session

this should simplify the task of creating a jar object to be manipulated
directly by the end user.
parent b9c984d7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -44,6 +44,12 @@ module HTTPX
          request
        end

        # factory method to return a Jar to the user, which can then manipulate
        # externally to the session.
        def make_jar(*args)
          Jar.new(*args)
        end

        private

        def set_request_callbacks(request)
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ module HTTPX

      module InstanceMethods
        def cookies: () -> Jar

        def make_jar: (*untyped) -> Jar
      end

      module HeadersMethods
+7 −0
Original line number Diff line number Diff line
@@ -3,6 +3,13 @@
require_relative "test_helper"

class CookieJarTest < Minitest::Test
  def test_plugin_cookies_make_jar
    session = HTTPX.plugin(:cookies)
    assert session.make_jar.is_a?(HTTPX::Plugins::Cookies::Jar)
    cookie = HTTPX::Plugins::Cookies::Cookie.new("a", "b")
    assert session.make_jar({ "a" => "b" }).each.to_a == [cookie]
  end

  def test_plugin_cookies_jar
    HTTPX.plugin(:cookies) # force loading the modules