mirror of
https://github.com/rclone/rclone
synced 2025-01-04 05:06:24 +01:00
rc: Fix serving bucket based objects with --rc-serve
Before this change serving bucket based objects `[remote:bucket]/path/to/object` would fail with 404 not found. This was because the leading `/` in `/path/to/object` was being passed to NewObject.
This commit is contained in:
parent
2c72e7f0a2
commit
f681d32996
@ -243,6 +243,7 @@ func (s *Server) serveRemote(w http.ResponseWriter, r *http.Request, path string
|
|||||||
}
|
}
|
||||||
directory.Serve(w, r)
|
directory.Serve(w, r)
|
||||||
} else {
|
} else {
|
||||||
|
path = strings.Trim(path, "/")
|
||||||
o, err := f.NewObject(path)
|
o, err := f.NewObject(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(path, nil, w, errors.Wrap(err, "failed to find object"), http.StatusInternalServerError)
|
writeError(path, nil, w, errors.Wrap(err, "failed to find object"), http.StatusInternalServerError)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -229,7 +230,7 @@ func TestRemoteServing(t *testing.T) {
|
|||||||
Expected: `{
|
Expected: `{
|
||||||
"error": "failed to find object: object not found",
|
"error": "failed to find object: object not found",
|
||||||
"input": null,
|
"input": null,
|
||||||
"path": "/notfound",
|
"path": "notfound",
|
||||||
"status": 404
|
"status": 404
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
@ -268,6 +269,14 @@ func TestRemoteServing(t *testing.T) {
|
|||||||
Headers: map[string]string{
|
Headers: map[string]string{
|
||||||
"Content-Length": "18",
|
"Content-Length": "18",
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
Name: "file with no slash after ]",
|
||||||
|
URL: strings.TrimRight(remoteURL, "/") + "file.txt",
|
||||||
|
Status: http.StatusOK,
|
||||||
|
Expected: "this is file1.txt\n",
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Content-Length": "18",
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
Name: "file2",
|
Name: "file2",
|
||||||
URL: remoteURL + "dir/file2.txt",
|
URL: remoteURL + "dir/file2.txt",
|
||||||
|
Loading…
Reference in New Issue
Block a user