forked from FRiCKLE/ngx_cache_purge
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(partial keys): Support partial keys to purge multiple keys.
Put an '*' at the end of your purge cache URL. e.g: proxy_cache_key $scheme$host$uri$is_args$args$cookie_JSESSIONID; curl -X PURGE https://example.com/pass* This will remove every cached page whose key cache starting with: httpsexample.com/pass* Be careful not passing any value for the values after the $uri, or put it at the end of your cache key. Signed-off-by: Francisco Miguel Biete <fbiete@gmail.com> Signed-off-by: Francisco Miguel Biete <fmbiete@gmail.com> Resolved FRiCKLE#33 Resolved FRiCKLE#35
- Loading branch information
Showing
3 changed files
with
318 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# vi:filetype=perl | ||
|
||
use lib 'lib'; | ||
use Test::Nginx::Socket; | ||
|
||
repeat_each(1); | ||
|
||
plan tests => 41; | ||
|
||
our $http_config = <<'_EOC_'; | ||
proxy_cache_path /tmp/ngx_cache_purge_cache keys_zone=test_cache:10m; | ||
proxy_temp_path /tmp/ngx_cache_purge_temp 1 2; | ||
_EOC_ | ||
|
||
our $config = <<'_EOC_'; | ||
location /proxy { | ||
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd; | ||
proxy_cache test_cache; | ||
proxy_cache_key $uri$is_args$args; | ||
proxy_cache_valid 3m; | ||
add_header X-Cache-Status $upstream_cache_status; | ||
proxy_cache_purge PURGE from 1.0.0.0/8 127.0.0.0/8 3.0.0.0/8; | ||
} | ||
location = /etc/passwd { | ||
root /var/www/html; | ||
} | ||
_EOC_ | ||
|
||
worker_connections(128); | ||
no_shuffle(); | ||
run_tests(); | ||
|
||
no_diff(); | ||
|
||
__DATA__ | ||
=== TEST 1: prepare passwd | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 2: prepare passwd2 | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd2 | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 3: prepare shadow | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/shadow | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 4: get from cache passwd | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
X-Cache-Status: HIT | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 5: get from cache passwd2 | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd2 | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
X-Cache-Status: HIT | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 6: purge from cache | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
PURGE /proxy/pass* | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/html | ||
--- response_body_like: Successful purge | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 7: get from empty cache passwd | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
X-Cache-Status: MISS | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 8: get from empty cache passwd2 | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/passwd2 | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
X-Cache-Status: MISS | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ | ||
=== TEST 9: get from cache shadow | ||
--- http_config eval: $::http_config | ||
--- config eval: $::config | ||
--- request | ||
GET /proxy/shadow | ||
--- error_code: 200 | ||
--- response_headers | ||
Content-Type: text/plain | ||
X-Cache-Status: HIT | ||
--- response_body_like: root | ||
--- timeout: 10 | ||
--- no_error_log eval | ||
qr/\[(warn|error|crit|alert|emerg)\]/ |