Skip to content

Commit

Permalink
http: add https client support
Browse files Browse the repository at this point in the history
Fixes #851.

R=rsc
CC=golang-dev
https://golang.org/cl/1729052
  • Loading branch information
fhs authored and rsc committed Jul 29, 2010
1 parent 518df52 commit 4f64ecf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pkg/crypto/tls/handshake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Conn) clientHandshake() os.Error {
}

// TODO(rsc): Find certificates for OS X 10.6.
if false && c.config.RootCAs != nil {
if c.config.RootCAs != nil {
root := c.config.RootCAs.FindParent(certs[len(certs)-1])
if root == nil {
return c.sendAlert(alertBadCertificate)
Expand Down
15 changes: 11 additions & 4 deletions src/pkg/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package http

import (
"bufio"
"crypto/tls"
"encoding/base64"
"fmt"
"io"
Expand All @@ -21,7 +22,7 @@ import (
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }

// Used in Send to implement io.ReadCloser by bundling together the
// io.BufReader through which we read the response, and the underlying
// bufio.Reader through which we read the response, and the underlying
// network connection.
type readClose struct {
io.Reader
Expand All @@ -34,13 +35,13 @@ type readClose struct {
// send() method is nonpublic because, when we refactor the code for persistent
// connections, it may no longer make sense to have a method with this signature.
func send(req *Request) (resp *Response, err os.Error) {
if req.URL.Scheme != "http" {
if req.URL.Scheme != "http" && req.URL.Scheme != "https" {
return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme}
}

addr := req.URL.Host
if !hasPort(addr) {
addr += ":http"
addr += ":" + req.URL.Scheme
}
info := req.URL.Userinfo
if len(info) > 0 {
Expand All @@ -52,7 +53,13 @@ func send(req *Request) (resp *Response, err os.Error) {
}
req.Header["Authorization"] = "Basic " + string(encoded)
}
conn, err := net.Dial("tcp", "", addr)

var conn io.ReadWriteCloser
if req.URL.Scheme == "http" {
conn, err = net.Dial("tcp", "", addr)
} else { // https
conn, err = tls.Dial("tcp", "", addr)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4f64ecf

Please sign in to comment.