mirror of
https://github.com/alibaba/higress.git
synced 2026-07-24 05:10:34 +08:00
fix(cache-control): emit standard max-age Cache-Control directive (#4118)
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
1.0.0
|
||||
1.0.0-alpha
|
||||
@@ -74,7 +74,7 @@ func onHttpResponseHeaders(ctx wrapper.HttpContext, config CacheControlConfig, l
|
||||
if hit {
|
||||
if config.expires == "max" {
|
||||
proxywasm.AddHttpResponseHeader("Expires", "Thu, 31 Dec 2037 23:55:55 GMT")
|
||||
proxywasm.AddHttpResponseHeader("Cache-Control", "maxAge=315360000")
|
||||
proxywasm.AddHttpResponseHeader("Cache-Control", "max-age=315360000")
|
||||
} else if config.expires == "epoch" {
|
||||
proxywasm.AddHttpResponseHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT")
|
||||
proxywasm.AddHttpResponseHeader("Cache-Control", "no-cache")
|
||||
@@ -83,7 +83,7 @@ func onHttpResponseHeaders(ctx wrapper.HttpContext, config CacheControlConfig, l
|
||||
currentTime := time.Now()
|
||||
expireTime := currentTime.Add(time.Duration(maxAge) * time.Second)
|
||||
proxywasm.AddHttpResponseHeader("Expires", expireTime.UTC().Format(http.TimeFormat))
|
||||
proxywasm.AddHttpResponseHeader("Cache-Control", "maxAge="+strconv.FormatInt(maxAge, 10))
|
||||
proxywasm.AddHttpResponseHeader("Cache-Control", "max-age="+strconv.FormatInt(maxAge, 10))
|
||||
}
|
||||
}
|
||||
return types.ActionContinue
|
||||
|
||||
@@ -234,7 +234,7 @@ func TestOnHttpResponseHeaders(t *testing.T) {
|
||||
// 验证是否添加了缓存控制头
|
||||
responseHeaders := host.GetResponseHeaders()
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=3600"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=3600"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
@@ -264,7 +264,7 @@ func TestOnHttpResponseHeaders(t *testing.T) {
|
||||
// 验证是否添加了缓存控制头
|
||||
responseHeaders := host.GetResponseHeaders()
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=315360000"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=315360000"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
@@ -354,7 +354,7 @@ func TestOnHttpResponseHeaders(t *testing.T) {
|
||||
// 验证是否添加了缓存控制头
|
||||
responseHeaders := host.GetResponseHeaders()
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=7200"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=7200"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
@@ -384,7 +384,7 @@ func TestOnHttpResponseHeaders(t *testing.T) {
|
||||
// 验证是否添加了缓存控制头
|
||||
responseHeaders := host.GetResponseHeaders()
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=1800"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=1800"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
@@ -414,7 +414,7 @@ func TestOnHttpResponseHeaders(t *testing.T) {
|
||||
// 验证是否添加了缓存控制头
|
||||
responseHeaders := host.GetResponseHeaders()
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=3600"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=3600"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
@@ -452,7 +452,7 @@ func TestCompleteFlow(t *testing.T) {
|
||||
|
||||
// 验证是否添加了必要的缓存控制响应头
|
||||
require.True(t, test.HasHeader(responseHeaders, "expires"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "maxAge=3600"))
|
||||
require.True(t, test.HasHeaderWithValue(responseHeaders, "cache-control", "max-age=3600"))
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ var WasmPluginCacheControl = suite.ConformanceTest{
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
Headers: map[string]string{
|
||||
"Cache-Control": "maxAge=3600",
|
||||
"Cache-Control": "max-age=3600",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -45,4 +45,4 @@ spec:
|
||||
configDisable: false
|
||||
ingress:
|
||||
- higress-conformance-infra/wasmplugin-cache-control
|
||||
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/cache-control:2.0.0
|
||||
url: file:///opt/plugins/wasm-go/extensions/cache-control/plugin.wasm
|
||||
|
||||
Reference in New Issue
Block a user