Skip to content

Commit

Permalink
The Authorization header should include the Basic keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Sep 27, 2019
1 parent dc9b54d commit 1d6a7e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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==",
":@": "",
"@": "",
"": "",
Expand Down
9 changes: 5 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,17 +1155,18 @@ 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)
}
buf := req.Header.bufKV.value[:0]
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])
}
}

Expand Down
1 change: 1 addition & 0 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ var (
strBytes = []byte("bytes")
strTextSlash = []byte("text/")
strApplicationSlash = []byte("application/")
strBasicSpace = []byte("Basic ")
)

0 comments on commit 1d6a7e0

Please sign in to comment.