mirror of
https://github.com/golang/go
synced 2024-11-25 07:07:57 -07:00
Add basic http authentication support.
Fixes #407. R=rsc, ajstarks CC=ushakov https://golang.org/cl/176076
This commit is contained in:
parent
5d754bfaea
commit
8e2608eca8
@ -8,6 +8,7 @@ package http
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@ -118,6 +119,16 @@ func send(req *Request) (resp *Response, err os.Error) {
|
||||
if !hasPort(addr) {
|
||||
addr += ":http"
|
||||
}
|
||||
info := req.URL.Userinfo
|
||||
if len(info) > 0 {
|
||||
enc := base64.URLEncoding
|
||||
encoded := make([]byte, enc.EncodedLen(len(info)))
|
||||
enc.Encode(encoded, strings.Bytes(info))
|
||||
if req.Header == nil {
|
||||
req.Header = make(map[string]string)
|
||||
}
|
||||
req.Header["Authorization"] = "Basic " + string(encoded)
|
||||
}
|
||||
conn, err := net.Dial("tcp", "", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user