]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: minor fixes and optimization for Response.TLS
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 5 Mar 2014 20:40:13 +0000 (12:40 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 5 Mar 2014 20:40:13 +0000 (12:40 -0800)
Also add it to doc/go1.3.txt.

Update #7289

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/71740043

doc/go1.3.txt
src/pkg/net/http/client_test.go
src/pkg/net/http/response.go
src/pkg/net/http/transport.go

index a5ebb2b9c6da55fe521d9bb73bd57ed5946b9292..7828ea17f5fb13c6722b55ef96c76f619d4db67a 100644 (file)
@@ -8,6 +8,7 @@ crypto/x509: support CSRs (CL 49830048)
 liblink: pull linker i/o into separate liblink C library (CL 35790044)
 misc/benchcmp: removed and replaced by go.tools/cmd/benchcmp (CL 47980043)
 misc/dist: renamed misc/makerelease (CL 39920043)
+net/http: add Request.TLS (CL 52660047)
 net/http: add Server.ErrorLog; log and test TLS handshake errors (CL 70250044)
 net/http: add Server.SetKeepAlivesEnabled (CL 69670043)
 net/http: add Transport.TLSHandshakeTimeout; set it by default (CL 68150045)
index 091fea04cb8258027ee826c1bbe0a749583eee22..bf5c776e3c7bd4f972fde484cf551a91ffbc26f2 100644 (file)
@@ -727,14 +727,13 @@ func TestResponseSetsTLSConnectionState(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
+       defer res.Body.Close()
        if res.TLS == nil {
                t.Fatal("Response didn't set TLS Connection State.")
        }
-       if res.TLS.CipherSuite != tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA {
-               t.Errorf("Unexpected TLS Cipher Suite: %d != %d",
-                       res.TLS.CipherSuite, tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA)
+       if got, want := res.TLS.CipherSuite, tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA; got != want {
+               t.Errorf("TLS Cipher Suite = %d; want %d", got, want)
        }
-       res.Body.Close()
 }
 
 // Verify Response.ContentLength is populated. http://golang.org/issue/4126
index 42e01682c26bdd8f69e35eaad84b0f19bd00d600..310c11c32a2a7c545d291fcac4a827ac05d370ad 100644 (file)
@@ -76,10 +76,10 @@ type Response struct {
        // This is only populated for Client requests.
        Request *Request
 
-       // TLS allows information about the TLS connection on which the
-       // response was received. The Transport in this package sets the field
-       // for TLS-enabled connections before returning the Response otherwise
-       // it leaves the field nil.
+       // TLS contains information about the TLS connection on which the
+       // response was received. It is nil for unencrypted responses.
+       // The pointer is shared between responses and should not be
+       // modified.
        TLS *tls.ConnectionState
 }
 
index f2896c4b02b567eae305e0e0de1c47c8ef60e1fc..bfdd01d0c015a346238e69691eac6564d0631362 100644 (file)
@@ -583,6 +583,8 @@ func (t *Transport) dialConn(cm connectMethod) (*persistConn, error) {
                                return nil, err
                        }
                }
+               cs := tlsConn.ConnectionState()
+               pconn.tlsState = &cs
                pconn.conn = tlsConn
        }
 
@@ -718,6 +720,7 @@ type persistConn struct {
        t        *Transport
        cacheKey connectMethodKey
        conn     net.Conn
+       tlsState *tls.ConnectionState
        closed   bool                // whether conn has been closed
        br       *bufio.Reader       // from conn
        bw       *bufio.Writer       // to conn
@@ -792,9 +795,8 @@ func (pc *persistConn) readLoop() {
                        }
                }
 
-               if tlsConn, ok := pc.conn.(*tls.Conn); resp != nil && ok {
-                       resp.TLS = new(tls.ConnectionState)
-                       *resp.TLS = tlsConn.ConnectionState()
+               if resp != nil {
+                       resp.TLS = pc.tlsState
                }
 
                hasBody := resp != nil && rc.req.Method != "HEAD" && resp.ContentLength != 0