Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): Caddy config cache_keys json parse error #460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions configurationtypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func (c *CacheKeys) parseJSON(rootDecoder *json.Decoder) {
var token json.Token
var err error

_, _ = rootDecoder.Token()
_, _ = rootDecoder.Token()
_, _ = rootDecoder.Token()

for err == nil {
Expand Down
37 changes: 37 additions & 0 deletions plugins/caddy/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,43 @@ func TestQueryString(t *testing.T) {
}
}

func TestCacheKeys(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
admin localhost:2999
order cache before rewrite
http_port 9080
https_port 9443
cache
}
localhost:9080 {
route /cache-keys {
cache {
cache_keys {
query= {
disable_query
}
query2= {
disable_body
disable_host
}
}
}
respond "Hello, query string!"
}
}`, "caddyfile")

resp1, _ := tester.AssertGetResponse(`http://localhost:9080/cache-keys?query=string`, 200, "Hello, query string!")
if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/cache-keys" {
t.Errorf("unexpected Cache-Status header %v", resp1.Header)
}
resp2, _ := tester.AssertGetResponse(`http://localhost:9080/cache-keys?foo=bar`, 200, "Hello, query string!")
if resp2.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/cache-keys?foo=bar" {
t.Errorf("unexpected Cache-Status header %v", resp2.Header)
}
}

func TestMaxAge(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
Expand Down
Loading