From 71781e2c3fa70147a7b741263300db58eb06997f Mon Sep 17 00:00:00 2001 From: Anirudh Katoch Date: Thu, 3 Jun 2021 02:34:06 +0530 Subject: [PATCH] http: Support for directory-lister for the http remote --- backend/http/http.go | 15 +++++++++++++++ backend/http/http_internal_test.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/backend/http/http.go b/backend/http/http.go index a5c367402..73704f0bf 100644 --- a/backend/http/http.go +++ b/backend/http/http.go @@ -296,11 +296,26 @@ var ( // parseName turns a name as found in the page into a remote path or returns an error func parseName(base *url.URL, name string) (string, error) { + // make URL absolute u, err := rest.URLJoin(base, name) if err != nil { return "", errURLJoinFailed } + + //Some vendors have the format path/to/?dir=dirname instead of path/to/dirname + //This can be corrected here to ignore the extranous "?dir=" + if(len(u.Query()["dir"]) == 1 && len(u.Query()) == 1 ) { + dirName := u.Query()["dir"][0] + name = name[:strings.Index(name, "?dir=")] + name = name + dirName + // make URL absolute + u, err = rest.URLJoin(base, name) + if err != nil { + return "", errURLJoinFailed + } + } + // check it doesn't have URL parameters uStr := u.String() if strings.Index(uStr, "?") >= 0 { diff --git a/backend/http/http_internal_test.go b/backend/http/http_internal_test.go index f2e791781..14a057868 100644 --- a/backend/http/http_internal_test.go +++ b/backend/http/http_internal_test.go @@ -251,6 +251,8 @@ func TestParseName(t *testing.T) { {"http://example.com/", "potato", nil, "potato"}, {"http://example.com/dir/", "potato", nil, "potato"}, {"http://example.com/dir/", "potato?download=true", errFoundQuestionMark, ""}, + {"http://example.com/dir/", "http://example.com/dir/?dir=sweet+potato", nil, "sweet potato"}, + {"http://example.com/dir/", "?dir=sweet+potato", nil, "sweet potato"}, {"http://example.com/dir/", "../dir/potato", nil, "potato"}, {"http://example.com/dir/", "..", errNotUnderRoot, ""}, {"http://example.com/dir/", "http://example.com/", errNotUnderRoot, ""},