darkweak / souin

An HTTP cache system, RFC compliant, compatible with @tyktechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @go-kratos, @gin-gonic, @roadrunner-server, @zalando, @zeromicro, @nginx and @apache

Home Page:https://docs.souin.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix(plugin/caddy): handle disable_query directive

frederichoule opened this issue · comments

We added the option to disable query string in keys (#319), which seemed to work according to the tests in context/key_test.go, but in real life situation it doesn't seem to work.

For example, a test in plugins/caddy/httpcache_test.go still appends the query string to the key.

func TestQueryString(t *testing.T) {
	tester := caddytest.NewTester(t)
	tester.InitServer(`
	{
		admin localhost:2999
		order cache before rewrite
		http_port     9080
		https_port    9443
		cache {
			key { 
				disable_query
			}
		}
	}
	localhost:9080 {
		route /cache-default {
			cache
			respond "Hello, default!"
		}
	}`, "caddyfile")

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

}

Results:

unexpected Cache-Status header map[Cache-Control:[] Cache-Status:[Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/cache-default?query=string]

Closed by #328