rack-strip-cookies 2.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 017b48f0fc3b8303d328dd5490fbe268e4be8ca533fcd67190241b63c293fcde
4
- data.tar.gz: 555c6902f8393e4fecb12f30a11e455b8408beb2c9c22855cb77d70f35f6e7dc
3
+ metadata.gz: bfb4b59e07b831256a03212bc6219d60ff755a0015a03954d0475e825a0196ee
4
+ data.tar.gz: f1861fc6961f221c8d08b97ad9900b4988287b5e0f5c714b690f8acafdbb179e
5
5
  SHA512:
6
- metadata.gz: 6ea00580d48e10ef4eff0b601c0f527bb06af2f856702c6267a33081d674c955dcfa6e81b105a34fdad522d69ac8d7eeccf63f076daad464a872669d8ed94b4a
7
- data.tar.gz: 259efb41fc07b7bee69c152e88fddb0a0d08b472a5926d168a71aa2931c477c4010909b2b85008825453169e362cf514f7d6aea9cbfc576c0d8bb0d6ac75d521
6
+ metadata.gz: 8abc1c9d1ba1a874f2f5466c878330b8572ff4a57b5ced4b0051b10a011c457efe66dcca8d561644ee1e84ce898da1678352f7eab8cf3ca43a8e39f0fcab3a73
7
+ data.tar.gz: 5159458d3994509f959c4d6584290af40a255a40e0b4cc1d7e2aa350eea60f0dd1bc6f70faa450acfdcbcc444fd549389b4dac60d3b62535e9f2e3ef5b8e3e57
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class StripCookies
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -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
- # Each pattern is a regex that represents either an exact match or a wildcard match.
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.
@@ -55,8 +57,8 @@ module Rack
55
57
  headers.delete(header_name) if header_name.to_s.casecmp?("set-cookie")
56
58
  end
57
59
 
58
- # Add a custom header 'Cookies-Stripped' to indicate that cookies were stripped.
59
- headers["cookies-stripped"] = "true"
60
+ # Expose the stripping decision only when explicitly enabled.
61
+ headers["cookies-stripped"] = "true" if expose_header
60
62
  else
61
63
  # If cookies are not to be stripped, simply call the next middleware or application.
62
64
  # The original request and response headers remain untouched.
@@ -80,9 +82,12 @@ module Rack
80
82
  # Wildcard pattern: "/api/*" -> matches "/api/" and "/api/anything"
81
83
  prefix = Regexp.escape(path.chomp("/*"))
82
84
  Regexp.new("^#{prefix}/.*$")
85
+ elsif path == "/"
86
+ # Root path matches every Rack path.
87
+ %r{\A/.*\z}
83
88
  else
84
- # Exact match pattern: "/api" -> matches only "/api"
85
- Regexp.new("^#{Regexp.escape(path)}$")
89
+ # Base path pattern: "/api" -> matches "/api" and "/api/anything"
90
+ Regexp.new("^#{Regexp.escape(path)}(?:$|/.*)")
86
91
  end
87
92
  end
88
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-strip-cookies
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Poli
@@ -79,7 +79,8 @@ dependencies:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: 5.18.0
82
- description: Rack middleware to remove cookies at user-defined paths.
82
+ description: Rack middleware that deletes cookies at designated paths, including support
83
+ for wildcard patterns for flexible cookie management.
83
84
  email:
84
85
  - claudio@icorete.ch
85
86
  executables: []
@@ -100,14 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
101
  requirements:
101
102
  - - ">="
102
103
  - !ruby/object:Gem::Version
103
- version: '0'
104
+ version: '3.0'
104
105
  required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  requirements:
106
107
  - - ">="
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 4.0.3
111
+ rubygems_version: 4.0.6
111
112
  specification_version: 4
112
113
  summary: Rack middleware to remove cookies at user-defined paths.
113
114
  test_files: []