-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(httpfs/consulfs): base URL query parameters weren't preserved (#696)
Signed-off-by: Dave Henderson <[email protected]>
- Loading branch information
1 parent
8ed1ecf
commit fa2a8fd
Showing
8 changed files
with
93 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package internal | ||
|
||
import "net/url" | ||
|
||
func SubURL(base *url.URL, name string) (*url.URL, error) { | ||
rel, err := url.Parse(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
u := base.ResolveReference(rel) | ||
|
||
// also merge query params | ||
if base.RawQuery != "" { | ||
bq := base.Query() | ||
rq := rel.Query() | ||
|
||
for k := range rq { | ||
bq.Set(k, rq.Get(k)) | ||
} | ||
|
||
u.RawQuery = bq.Encode() | ||
} | ||
|
||
return u, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hairyhenderson/go-fsimpl/internal/tests" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSubURL(t *testing.T) { | ||
base := tests.MustURL("https://example.com/dir/") | ||
sub, err := SubURL(base, "sub") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "https://example.com/dir/sub", sub.String()) | ||
|
||
base = tests.MustURL("consul:///dir/") | ||
sub, err = SubURL(base, "sub/foo?param=foo") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "consul:///dir/sub/foo?param=foo", sub.String()) | ||
|
||
base = tests.MustURL("vault:///dir/?param1=foo¶m2=bar") | ||
sub, err = SubURL(base, "sub/foo") | ||
require.NoError(t, err) | ||
assert.Equal(t, "vault:///dir/sub/foo?param1=foo¶m2=bar", sub.String()) | ||
|
||
base = tests.MustURL("consul:///dir/?param1=foo¶m2=bar") | ||
sub, err = SubURL(base, "sub/foo?param3=baz") | ||
require.NoError(t, err) | ||
assert.Equal(t, "consul:///dir/sub/foo?param1=foo¶m2=bar¶m3=baz", sub.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters