fix: resolve http non encode attachment filename (#975)

This commit is contained in:
Levi authored and GitHub committed 2025-04-05 22:37:19 +08:00
1 parent 50bc9ab129
commit cd5fd45667
4 files changed
+39 -2

No files matched your search

+14
View File
@@ -174,6 +174,12 @@ func (f *Fetcher) Resolve(req *base.Request) error {
} else {
file.Name = filename
}
} else {
substr := "attachment; filename="
index := strings.Index(contentDisposition, substr)
if index != -1 {
file.Name = contentDisposition[index+len(substr):]
}
}
}
// get file filePath by URL
@@ -610,6 +616,14 @@ func (f *Fetcher) buildClient() *http.Client {
}
}
func decodeMangledString(mangled string) string {
rawBytes := make([]byte, 0, len(mangled)*3)
for _, r := range mangled {
rawBytes = append(rawBytes, byte(r))
}
return string(rawBytes)
}
type fetcherData struct {
Connections []*connection
}
+10
View File
@@ -47,6 +47,16 @@ func TestFetcher_Resolve(t *testing.T) {
},
},
}, t)
testResolve(test.StartTestCustomServer, "no-encode", &base.Resource{
Size: test.BuildSize,
Range: false,
Files: []*base.FileInfo{
{
Name: "测试.zip",
Size: test.BuildSize,
},
},
}, t)
testResolve(test.StartTestCustomServer, "%E6%B5%8B%E8%AF%95.zip", &base.Resource{
Size: 0,
Range: false,