when users pass a Cookie header as option and plugin is enabled, the header will be parsed and managed by the jar

This commit is contained in:
HoneyryderChuck 2021-07-15 15:07:40 +01:00
parent ac398ae0f0
commit 3ae18120d2
2 changed files with 17 additions and 2 deletions

View File

@ -75,6 +75,21 @@ module HTTPX
add("cookie", header_value)
end
end
module OptionsMethods
def initialize(*)
super
return unless @headers.key?("cookie")
@headers.delete("cookie").each do |ck|
ck.split(/ *; */).each do |cookie|
name, value = cookie.split("=", 2)
@cookies.add(Cookie.new(name, value))
end
end
end
end
end
register_plugin :cookies, Cookies
end

View File

@ -12,7 +12,7 @@ module HTTPX
def []=: (headers_key field, headers_value value) -> void
def add: (headers_key field, string value) -> void
def delete: (headers_key field) -> void
def delete: (headers_key field) -> Array[String]?
def each: (?_Each[[headers_key, String]]? extra_headers) { (headers_key, String) -> void } -> void
| (?_Each[[headers_key, String]]? extra_headers) -> Enumerable[[headers_key, String]]
@ -28,7 +28,7 @@ module HTTPX
def to_hash: () -> Hash[headers_key, String]
alias to_h to_hash
def inspect: () -> String
def inspect: () -> String
private