feat(offline_download): add simple http tool (close #4002)
This commit is contained in:
21
internal/offline_download/http/util.go
Normal file
21
internal/offline_download/http/util.go
Normal file
@ -0,0 +1,21 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
)
|
||||
|
||||
func parseFilenameFromContentDisposition(contentDisposition string) (string, error) {
|
||||
if contentDisposition == "" {
|
||||
return "", fmt.Errorf("Content-Disposition is empty")
|
||||
}
|
||||
_, params, err := mime.ParseMediaType(contentDisposition)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filename := params["filename"]
|
||||
if filename == "" {
|
||||
return "", fmt.Errorf("filename not found in Content-Disposition: [%s]", contentDisposition)
|
||||
}
|
||||
return filename, nil
|
||||
}
|
Reference in New Issue
Block a user