代码拉取完成,页面将自动刷新
同步操作将从 楠木/gzip 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package gzip
import (
"net/http"
"net/url"
"testing"
)
func TestCommonCaseFilter_ShouldCompress(t *testing.T) {
tests := []struct {
name string
req *http.Request
want bool
}{
{
name: "Good request",
req: &http.Request{Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: true,
},
{
name: "HEAD request",
req: &http.Request{Method: http.MethodHead, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: false,
},
{
name: "HTTP2 upgrade request",
req: &http.Request{Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}, "Upgrade": {"http2"}}},
want: false,
},
{
name: "Not accepting gzip request",
req: &http.Request{Method: http.MethodPost},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewCommonRequestFilter()
if got := c.ShouldCompress(tt.req); got != tt.want {
t.Errorf("ShouldCompress() = %v, want %v", got, tt.want)
}
})
}
}
func TestExtensionFilter_ShouldCompress(t *testing.T) {
tests := []struct {
name string
req *http.Request
want bool
}{
{
name: "no ext",
req: &http.Request{URL: mustParseURL("https://example.com/hello"), Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: true,
},
{
name: "txt",
req: &http.Request{URL: mustParseURL("https://example.com/a.txt"), Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: true,
},
{
name: "md",
req: &http.Request{URL: mustParseURL("https://example.com/a.txt.md"), Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: true,
},
{
name: "png",
req: &http.Request{URL: mustParseURL("https://example.com/a.exe.png"), Method: http.MethodPost, Header: map[string][]string{"Accept-Encoding": {"gzip"}}},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := DefaultExtensionFilter()
if got := e.ShouldCompress(tt.req); got != tt.want {
t.Errorf("ShouldCompress() = %v, want %v", got, tt.want)
}
})
}
}
func mustParseURL(rawurl string) (URL *url.URL) {
URL, err := url.Parse(rawurl)
if err != nil {
panic(err)
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。