Replace the parsing cookie logic instead of cookiejar gem
This commit is contained in:
parent
259ad9bc5a
commit
f065acbd63
1
Gemfile
1
Gemfile
|
@ -4,7 +4,6 @@ gem 'rails'
|
|||
gem 'rack'
|
||||
gem 'rack-proxy'
|
||||
gem 'addressable'
|
||||
gem 'cookiejar', '~> 0.3.2'
|
||||
|
||||
# Add dependencies to develop your gem here.
|
||||
# Include everything needed to run rake, tests, features, etc.
|
||||
|
|
|
@ -39,7 +39,6 @@ GEM
|
|||
addressable (2.3.8)
|
||||
arel (6.0.0)
|
||||
builder (3.2.2)
|
||||
cookiejar (0.3.2)
|
||||
descendants_tracker (0.0.4)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
docile (1.1.5)
|
||||
|
@ -149,7 +148,6 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
addressable
|
||||
bundler (~> 1.0)
|
||||
cookiejar (~> 0.3.2)
|
||||
jeweler (~> 2.0.1)
|
||||
rack
|
||||
rack-proxy
|
||||
|
@ -157,3 +155,6 @@ DEPENDENCIES
|
|||
rdoc (~> 3.12)
|
||||
shoulda
|
||||
simplecov
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'rack'
|
||||
require 'rack-proxy'
|
||||
require 'cookiejar'
|
||||
|
||||
module ReverseProxy
|
||||
class Client
|
||||
|
@ -92,11 +91,8 @@ module ReverseProxy
|
|||
set_cookies_hash = {}
|
||||
|
||||
set_cookie_headers.each do |set_cookie_header|
|
||||
set_cookie_hash = CookieJar::CookieValidation.parse_set_cookie(set_cookie_header)
|
||||
set_cookie_hash[:value] = CGI.unescape(set_cookie_hash[:value])
|
||||
|
||||
name = set_cookie_hash.delete(:name)
|
||||
|
||||
set_cookie_hash = parse_cookie(set_cookie_header)
|
||||
name = set_cookie_hash[:name]
|
||||
set_cookies_hash[name] = set_cookie_hash
|
||||
end
|
||||
|
||||
|
@ -140,5 +136,40 @@ module ReverseProxy
|
|||
def reconstruct_header_name(name)
|
||||
name.sub(/^HTTP_/, "").gsub("_", "-")
|
||||
end
|
||||
|
||||
COOKIE_PARAM_PATTERN = /\A([^(),\/<>@;:\\\"\[\]?={}\s]+)(?:=([^;]*))?\Z/
|
||||
COOKIE_SPLIT_PATTERN = /;\s*/
|
||||
|
||||
def parse_cookie(cookie_str)
|
||||
params = cookie_str.split(COOKIE_SPLIT_PATTERN)
|
||||
info = params.shift.match(COOKIE_PARAM_PATTERN)
|
||||
return {} unless info
|
||||
|
||||
cookie = {
|
||||
name: info[1],
|
||||
value: CGI.unescape(info[2]),
|
||||
}
|
||||
|
||||
params.each do |param|
|
||||
result = param.match(COOKIE_PARAM_PATTERN)
|
||||
next unless result
|
||||
|
||||
key = result[1].downcase.to_sym
|
||||
value = result[2]
|
||||
case key
|
||||
when :expires
|
||||
begin
|
||||
cookie[:expires] = Time.parse(value)
|
||||
rescue ArgumentError
|
||||
end
|
||||
when *[:httponly, :secure]
|
||||
cookie[key] = true
|
||||
else
|
||||
cookie[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
cookie
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue