Skip to content

Commit

Permalink
feat(gateway): Content-Disposition for legacy clients
Browse files Browse the repository at this point in the history
This adds ASCII-only filename for clients that do not implement RFC 5987

Closes #7648


This commit was moved from ipfs/kubo@19ec5f4
  • Loading branch information
lidel committed Sep 16, 2020
1 parent 95182c2 commit d92fd64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
ipnsPathPrefix = "/ipns/"
)

var onlyAscii = regexp.MustCompile("[[:^ascii:]]")

// gatewayHandler is a HTTP handler that serves IPFS objects (accessible by default at /ipfs/<path>)
// (it serves requests like GET /ipfs/QmVRzPKPzNtSrEzBFm2UZfxmPAgnaLke4DMcerbsGGSaFe/link)
type gatewayHandler struct {
Expand Down Expand Up @@ -265,7 +267,9 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
if r.URL.Query().Get("download") == "true" {
disposition = "attachment"
}
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename*=UTF-8''%s", disposition, url.PathEscape(urlFilename)))
utf8Name := url.PathEscape(urlFilename)
asciiName := url.PathEscape(onlyAscii.ReplaceAllLiteralString(urlFilename, "_"))
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"; filename*=UTF-8''%s", disposition, asciiName, utf8Name))
name = urlFilename
} else {
name = getFilename(urlPath)
Expand Down

0 comments on commit d92fd64

Please sign in to comment.