Commit 8e2608ec authored by Ivan Krasin's avatar Ivan Krasin Committed by Russ Cox

Add basic http authentication support.

Fixes #407.

R=rsc, ajstarks
CC=ushakov
https://golang.org/cl/176076
parent 5d754bfa
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment