fix(tus): preserve percent-encoded upload paths in Location header (#5817)
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
@@ -112,12 +112,12 @@ func tusPostHandler(cache UploadCache) handleFunc {
|
|||||||
// Enables the user to utilize the PATCH endpoint for uploading file data
|
// Enables the user to utilize the PATCH endpoint for uploading file data
|
||||||
cache.Register(file.RealPath(), uploadLength)
|
cache.Register(file.RealPath(), uploadLength)
|
||||||
|
|
||||||
path, err := url.JoinPath("/", d.server.BaseURL, "/api/tus", r.URL.Path)
|
basePath := "/" + strings.Trim(strings.TrimSpace(d.server.BaseURL), "/")
|
||||||
if err != nil {
|
if basePath == "/" {
|
||||||
return http.StatusBadRequest, fmt.Errorf("invalid path: %w", err)
|
basePath = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Location", path)
|
w.Header().Set("Location", basePath+"/api/tus"+r.URL.EscapedPath())
|
||||||
return http.StatusCreated, nil
|
return http.StatusCreated, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user