Skip to content

Commit

Permalink
Merge pull request ipfs/kubo#4177 from Voker57/feat/gw-filename-option
Browse files Browse the repository at this point in the history
Set filename in Content-Disposition if filename=x is passed in URI query

This commit was moved from ipfs/kubo@fcc96a3
  • Loading branch information
Stebalien authored Aug 21, 2018
2 parents 0d7e854 + 475fb8e commit abbd256
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
gopath "path"
"runtime/debug"
Expand Down Expand Up @@ -259,7 +260,14 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}

if !dir {
name := gopath.Base(urlPath)
urlFilename := r.URL.Query().Get("filename")
var name string
if urlFilename != "" {
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename*=UTF-8''%s", url.PathEscape(urlFilename)))
name = urlFilename
} else {
name = gopath.Base(urlPath)
}
i.serveFile(w, r, name, modtime, dr)
return
}
Expand Down

0 comments on commit abbd256

Please sign in to comment.