mirror of
https://github.com/hanzoai/oxy.git
synced 2026-09-30 23:42:31 +00:00
fix: UserInfo copy in CopyUrl
This commit is contained in:
@@ -140,8 +140,6 @@ issues:
|
||||
text: "context-keys-type: should not use basic type string as key" # TODO(ldez) must be fixed
|
||||
- path: .*_test.go
|
||||
text: "SA1029: should not use built-in type string as key for value" # TODO(ldez) must be fixed
|
||||
- path: utils/netutils.go
|
||||
text: "SA4001: &\\*x will be simplified to x. It will not copy x." # TODO(ldez) must be fixed
|
||||
- path: cbreaker/cbreaker_test.go
|
||||
text: "`statsNetErrors` - `threshold` always receives `0.6`" # TODO(ldez) must be fixed
|
||||
- path: buffer/buffer.go
|
||||
|
||||
+3
-2
@@ -160,13 +160,14 @@ func NopWriteCloser(w io.Writer) io.WriteCloser {
|
||||
func CopyURL(i *url.URL) *url.URL {
|
||||
out := *i
|
||||
if i.User != nil {
|
||||
out.User = &(*i.User)
|
||||
u := *i.User
|
||||
out.User = &u
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
// CopyHeaders copies http headers from source to destination, it
|
||||
// does not overide, but adds multiple headers.
|
||||
// does not override, but adds multiple headers.
|
||||
func CopyHeaders(dst http.Header, src http.Header) {
|
||||
for k, vv := range src {
|
||||
dst[k] = append(dst[k], vv...)
|
||||
|
||||
+10
-3
@@ -8,9 +8,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Make sure copy does it right, so the copied url
|
||||
// is safe to alter without modifying the other.
|
||||
// Make sure copy does it right, so the copied url is safe to alter without modifying the other.
|
||||
func TestCopyUrl(t *testing.T) {
|
||||
userinfo := url.UserPassword("foo", "secret")
|
||||
|
||||
urlA := &url.URL{
|
||||
Scheme: "http",
|
||||
Host: "localhost:5000",
|
||||
@@ -18,13 +19,19 @@ func TestCopyUrl(t *testing.T) {
|
||||
Opaque: "opaque",
|
||||
RawQuery: "a=1&b=2",
|
||||
Fragment: "#hello",
|
||||
User: &url.Userinfo{},
|
||||
User: userinfo,
|
||||
}
|
||||
|
||||
urlB := CopyURL(urlA)
|
||||
assert.Equal(t, urlA, urlB)
|
||||
|
||||
*userinfo = *url.User("bar")
|
||||
|
||||
assert.Equal(t, urlA.User, userinfo)
|
||||
assert.NotEqual(t, urlA.User, urlB.User)
|
||||
|
||||
urlB.Scheme = "https"
|
||||
|
||||
assert.NotEqual(t, urlA, urlB)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user