mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
Merge pull request #4177 from Voker57/feat/gw-filename-option
Set filename in Content-Disposition if filename=x is passed in URI query
This commit is contained in:
commit
fcc96a3ae7
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
gopath "path"
|
||||
"runtime/debug"
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -31,6 +31,11 @@ test_expect_success "GET IPFS path succeeds" '
|
||||
curl -sfo actual "http://127.0.0.1:$port/ipfs/$HASH"
|
||||
'
|
||||
|
||||
test_expect_success "GET IPFS path with explicit filename succeeds with proper header" "
|
||||
curl -fo actual -D actual_headers 'http://127.0.0.1:$port/ipfs/$HASH?filename=testтест' &&
|
||||
grep -F \"Content-Disposition: inline; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82\" actual_headers
|
||||
"
|
||||
|
||||
test_expect_success "GET IPFS path output looks good" '
|
||||
test_cmp expected actual &&
|
||||
rm actual
|
||||
|
||||
Loading…
Reference in New Issue
Block a user