diff --git a/client_test.go b/client_test.go index 987135011b..579a1236c5 100644 --- a/client_test.go +++ b/client_test.go @@ -21,8 +21,8 @@ import ( func TestClientURLAuth(t *testing.T) { cases := map[string]string{ - "user:pass@": "dXNlcjpwYXNz", - "foo:@": "Zm9vOg==", + "user:pass@": "Basic dXNlcjpwYXNz", + "foo:@": "Basic Zm9vOg==", ":@": "", "@": "", "": "", diff --git a/http.go b/http.go index 99782a852c..d10c9b161d 100644 --- a/http.go +++ b/http.go @@ -1155,7 +1155,8 @@ func (req *Request) Write(w *bufio.Writer) error { // So we are free to use RequestHeader.bufKV.value as a scratch pad for // the base64 encoding. nl := len(uri.username) + len(uri.password) + 1 - tl := nl + base64.StdEncoding.EncodedLen(nl) + nb := nl + len(strBasicSpace) + tl := nb + base64.StdEncoding.EncodedLen(nl) if tl > cap(req.Header.bufKV.value) { req.Header.bufKV.value = make([]byte, 0, tl) } @@ -1163,9 +1164,9 @@ func (req *Request) Write(w *bufio.Writer) error { buf = append(buf, uri.username...) buf = append(buf, strColon...) buf = append(buf, uri.password...) - buf = buf[:tl] - base64.StdEncoding.Encode(buf[nl:], buf[:nl]) - req.Header.SetBytesKV(strAuthorization, buf[nl:]) + buf = append(buf, strBasicSpace...) + base64.StdEncoding.Encode(buf[nb:tl], buf[:nl]) + req.Header.SetBytesKV(strAuthorization, buf[nl:tl]) } } diff --git a/strings.go b/strings.go index 343544ad18..12f1926308 100644 --- a/strings.go +++ b/strings.go @@ -81,4 +81,5 @@ var ( strBytes = []byte("bytes") strTextSlash = []byte("text/") strApplicationSlash = []byte("application/") + strBasicSpace = []byte("Basic ") )