mirror of
https://github.com/golang/go
synced 2024-11-13 19:30:22 -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 (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -118,6 +119,16 @@ func send(req *Request) (resp *Response, err os.Error) {
|
|||||||
if !hasPort(addr) {
|
if !hasPort(addr) {
|
||||||
addr += ":http"
|
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)
|
conn, err := net.Dial("tcp", "", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user