Skip to content

Commit

Permalink
fix(review): from hussam-almarzoq
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Apr 22, 2024
1 parent 7c3b8ba commit 04defb0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ cache_keys:
disable_host: true # Prevent the host from being used in the cache key
disable_method: true # Prevent the method from being used in the cache key
disable_query: true # Prevent the query string from being used in the cache key
disable_scheme: true # request scheme the query string from being used in the cache key
hash: true # Hash the cache key instead of a plaintext one
hide: true # Prevent the cache key to be in the response Cache-Status header
headers: # Add headers to the key
- Authorization # Add the header value in the key
- Content-Type # Add the header value in the key
Expand All @@ -107,6 +110,9 @@ default_cache:
disable_host: true # Prevent the host from being used in the cache key
disable_method: true # Prevent the method from being used in the cache key
disable_query: true # Prevent the query string from being used in the cache key
disable_scheme: true # Prevent the request scheme string from being used in the cache key
hash: true # Hash the cache key instead of a plaintext one
hide: true # Prevent the cache key to be in the response Cache-Status header
headers: # Add headers to the key
- Authorization # Add the header value in the key
- Content-Type # Add the header value in the key
Expand Down Expand Up @@ -172,6 +178,8 @@ surrogate_keys:
| `cache_keys.{your regexp}.disable_host` | Disable the host part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_method` | Disable the method part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_query` | Disable the query string part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.disable_scheme` | Disable the request scheme string part in the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.hash` | Hash the key matching the regexp | `true`<br/><br/>`(default: false)` |
| `cache_keys.{your regexp}.headers` | Add headers to the key matching the regexp | `- Authorization`<br/><br/>`- Content-Type`<br/><br/>`- X-Additional-Header` |
| `cache_keys.{your regexp}.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
| `cdn` | The CDN management, if you use any cdn to proxy your requests Souin will handle that | |
Expand All @@ -197,6 +205,8 @@ surrogate_keys:
| `default_cache.key.disable_host` | Disable the host part in the key | `true`<br/><br/>`(default: false)` |
| `default_cache.key.disable_method` | Disable the method part in the key | `true`<br/><br/>`(default: false)` |
| `default_cache.key.disable_query` | Disable the query string part in the key | `true`<br/><br/>`(default: false)` |
| `default_cache.key.disable_scheme` | Disable the request scheme string part in the key | `true`<br/><br/>`(default: false)` |
| `default_cache.key.hash` | Hash the key name in the storage | `true`<br/><br/>`(default: false)` |
| `default_cache.key.headers` | Add headers to the key matching the regexp | `- Authorization`<br/><br/>`- Content-Type`<br/><br/>`- X-Additional-Header` |
| `default_cache.key.hide` | Prevent the key from being exposed in the `Cache-Status` HTTP response header | `true`<br/><br/>`(default: false)` |
| `default_cache.mode` | RFC respect tweaking | One of `bypass` `bypass_request` `bypass_response` `strict` (default `strict`) |
Expand Down Expand Up @@ -468,8 +478,10 @@ There is the fully configuration below
disable_host
disable_method
disable_query
disable_scheme
headers X-Token Authorization
hide
hash
}
}
cdn {
Expand All @@ -488,6 +500,9 @@ There is the fully configuration below
disable_host
disable_method
disable_query
disable_scheme
hash
hide
headers Content-Type Authorization
}
log_level debug
Expand Down
8 changes: 7 additions & 1 deletion pkg/api/souin.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ func (s *SouinAPI) purgeMapping() {
}

if updated {
_ = current.Set(storage.MappingKeyPrefix+k, []byte{}, configurationtypes.URL{}, infiniteStoreDuration)
buf := new(bytes.Buffer)
e = gob.NewEncoder(buf).Encode(mapping)
if e != nil {
fmt.Println("Impossible to re-encode the mapping", storage.MappingKeyPrefix+k)
current.Delete(storage.MappingKeyPrefix + k)
}
_ = current.Set(storage.MappingKeyPrefix+k, buf.Bytes(), configurationtypes.URL{}, infiniteStoreDuration)
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/storage/redisProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ func (provider *Redis) ListKeys() []string {
for _, element := range scan.Elements {
value := provider.Get(element)
mapping, err := decodeMapping(value)
if err == nil {
for _, v := range mapping.Mapping {
if !v.FreshTime.Before(time.Now()) || !v.StaleTime.Before(time.Now()) {
elements = append(elements, v.RealKey)
}
if err != nil {
continue
}

for _, v := range mapping.Mapping {
if v.FreshTime.Before(time.Now()) && v.StaleTime.Before(time.Now()) {
continue
}
elements = append(elements, v.RealKey)
}
}
}
Expand Down

0 comments on commit 04defb0

Please sign in to comment.