rack-strip-cookies 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rack/strip-cookies/version.rb +1 -1
- data/lib/rack/strip-cookies.rb +15 -8
- metadata +6 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bfb4b59e07b831256a03212bc6219d60ff755a0015a03954d0475e825a0196ee
|
|
4
|
+
data.tar.gz: f1861fc6961f221c8d08b97ad9900b4988287b5e0f5c714b690f8acafdbb179e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8abc1c9d1ba1a874f2f5466c878330b8572ff4a57b5ced4b0051b10a011c457efe66dcca8d561644ee1e84ce898da1678352f7eab8cf3ca43a8e39f0fcab3a73
|
|
7
|
+
data.tar.gz: 5159458d3994509f959c4d6584290af40a255a40e0b4cc1d7e2aa350eea60f0dd1bc6f70faa450acfdcbcc444fd549389b4dac60d3b62535e9f2e3ef5b8e3e57
|
data/lib/rack/strip-cookies.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# lib/rack/strip-cookies.rb
|
|
2
2
|
module Rack
|
|
3
3
|
class StripCookies
|
|
4
|
-
attr_reader :app, :patterns, :invert
|
|
4
|
+
attr_reader :app, :patterns, :invert, :expose_header
|
|
5
5
|
|
|
6
6
|
# Initializes the middleware.
|
|
7
7
|
#
|
|
@@ -14,6 +14,7 @@ module Rack
|
|
|
14
14
|
def initialize(app, options = {})
|
|
15
15
|
@app = app
|
|
16
16
|
@invert = options.fetch(:invert, false)
|
|
17
|
+
@expose_header = options.fetch(:expose_header, false)
|
|
17
18
|
@patterns = compile_patterns(options[:paths] || [])
|
|
18
19
|
end
|
|
19
20
|
|
|
@@ -31,7 +32,8 @@ module Rack
|
|
|
31
32
|
path = env["PATH_INFO"] || "/"
|
|
32
33
|
|
|
33
34
|
# Determine if the current path matches any of the compiled patterns.
|
|
34
|
-
#
|
|
35
|
+
# Non-wildcard paths match both the exact path and any descendant path.
|
|
36
|
+
# Wildcard paths only match descendant paths.
|
|
35
37
|
matched = patterns.any? { |regex| regex.match?(path) }
|
|
36
38
|
|
|
37
39
|
# Decide whether to strip cookies based on the matching result and the invert flag.
|
|
@@ -50,11 +52,13 @@ module Rack
|
|
|
50
52
|
# This returns the HTTP status, headers, and body of the response.
|
|
51
53
|
status, headers, body = @app.call(env)
|
|
52
54
|
|
|
53
|
-
# Remove the 'Set-Cookie' header from the response headers.
|
|
54
|
-
headers.
|
|
55
|
+
# Remove any case variant of the 'Set-Cookie' header from the response headers.
|
|
56
|
+
headers.keys.each do |header_name|
|
|
57
|
+
headers.delete(header_name) if header_name.to_s.casecmp?("set-cookie")
|
|
58
|
+
end
|
|
55
59
|
|
|
56
|
-
#
|
|
57
|
-
headers["cookies-stripped"] = "true"
|
|
60
|
+
# Expose the stripping decision only when explicitly enabled.
|
|
61
|
+
headers["cookies-stripped"] = "true" if expose_header
|
|
58
62
|
else
|
|
59
63
|
# If cookies are not to be stripped, simply call the next middleware or application.
|
|
60
64
|
# The original request and response headers remain untouched.
|
|
@@ -78,9 +82,12 @@ module Rack
|
|
|
78
82
|
# Wildcard pattern: "/api/*" -> matches "/api/" and "/api/anything"
|
|
79
83
|
prefix = Regexp.escape(path.chomp("/*"))
|
|
80
84
|
Regexp.new("^#{prefix}/.*$")
|
|
85
|
+
elsif path == "/"
|
|
86
|
+
# Root path matches every Rack path.
|
|
87
|
+
%r{\A/.*\z}
|
|
81
88
|
else
|
|
82
|
-
#
|
|
83
|
-
Regexp.new("^#{Regexp.escape(path)}
|
|
89
|
+
# Base path pattern: "/api" -> matches "/api" and "/api/anything"
|
|
90
|
+
Regexp.new("^#{Regexp.escape(path)}(?:$|/.*)")
|
|
84
91
|
end
|
|
85
92
|
end
|
|
86
93
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rack-strip-cookies
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Claudio Poli
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rack
|
|
@@ -80,7 +79,8 @@ dependencies:
|
|
|
80
79
|
- - ">="
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
81
|
version: 5.18.0
|
|
83
|
-
description: Rack middleware
|
|
82
|
+
description: Rack middleware that deletes cookies at designated paths, including support
|
|
83
|
+
for wildcard patterns for flexible cookie management.
|
|
84
84
|
email:
|
|
85
85
|
- claudio@icorete.ch
|
|
86
86
|
executables: []
|
|
@@ -94,7 +94,6 @@ homepage: http://github.com/icoretech/rack-strip-cookies
|
|
|
94
94
|
licenses:
|
|
95
95
|
- MIT
|
|
96
96
|
metadata: {}
|
|
97
|
-
post_install_message:
|
|
98
97
|
rdoc_options: []
|
|
99
98
|
require_paths:
|
|
100
99
|
- lib
|
|
@@ -102,15 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
102
101
|
requirements:
|
|
103
102
|
- - ">="
|
|
104
103
|
- !ruby/object:Gem::Version
|
|
105
|
-
version: '0'
|
|
104
|
+
version: '3.0'
|
|
106
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
106
|
requirements:
|
|
108
107
|
- - ">="
|
|
109
108
|
- !ruby/object:Gem::Version
|
|
110
109
|
version: '0'
|
|
111
110
|
requirements: []
|
|
112
|
-
rubygems_version:
|
|
113
|
-
signing_key:
|
|
111
|
+
rubygems_version: 4.0.6
|
|
114
112
|
specification_version: 4
|
|
115
113
|
summary: Rack middleware to remove cookies at user-defined paths.
|
|
116
114
|
test_files: []
|