LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // HTTP client implementation. See RFC 2616. | 5 // HTTP client implementation. See RFC 2616. |
6 // | 6 // |
7 // This is the low-level Transport implementation of RoundTripper. | 7 // This is the low-level Transport implementation of RoundTripper. |
8 // The high-level interface is in client.go. | 8 // The high-level interface is in client.go. |
9 | 9 |
10 package http | 10 package http |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 if err := <-errc; err != nil { | 576 if err := <-errc; err != nil { |
577 plainConn.Close() | 577 plainConn.Close() |
578 return nil, err | 578 return nil, err |
579 } | 579 } |
580 if !cfg.InsecureSkipVerify { | 580 if !cfg.InsecureSkipVerify { |
581 if err := tlsConn.VerifyHostname(cfg.ServerName); err !=
nil { | 581 if err := tlsConn.VerifyHostname(cfg.ServerName); err !=
nil { |
582 plainConn.Close() | 582 plainConn.Close() |
583 return nil, err | 583 return nil, err |
584 } | 584 } |
585 } | 585 } |
| 586 cs := tlsConn.ConnectionState() |
| 587 pconn.tlsState = &cs |
586 pconn.conn = tlsConn | 588 pconn.conn = tlsConn |
587 } | 589 } |
588 | 590 |
589 pconn.br = bufio.NewReader(pconn.conn) | 591 pconn.br = bufio.NewReader(pconn.conn) |
590 pconn.bw = bufio.NewWriter(pconn.conn) | 592 pconn.bw = bufio.NewWriter(pconn.conn) |
591 go pconn.readLoop() | 593 go pconn.readLoop() |
592 go pconn.writeLoop() | 594 go pconn.writeLoop() |
593 return pconn, nil | 595 return pconn, nil |
594 } | 596 } |
595 | 597 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 // Only used by tests. | 713 // Only used by tests. |
712 return fmt.Sprintf("%s|%s|%s", k.proxy, k.scheme, k.addr) | 714 return fmt.Sprintf("%s|%s|%s", k.proxy, k.scheme, k.addr) |
713 } | 715 } |
714 | 716 |
715 // persistConn wraps a connection, usually a persistent one | 717 // persistConn wraps a connection, usually a persistent one |
716 // (but may be used for non-keep-alive requests as well) | 718 // (but may be used for non-keep-alive requests as well) |
717 type persistConn struct { | 719 type persistConn struct { |
718 t *Transport | 720 t *Transport |
719 cacheKey connectMethodKey | 721 cacheKey connectMethodKey |
720 conn net.Conn | 722 conn net.Conn |
| 723 tlsState *tls.ConnectionState |
721 closed bool // whether conn has been closed | 724 closed bool // whether conn has been closed |
722 br *bufio.Reader // from conn | 725 br *bufio.Reader // from conn |
723 bw *bufio.Writer // to conn | 726 bw *bufio.Writer // to conn |
724 reqch chan requestAndChan // written by roundTrip; read by readLoop | 727 reqch chan requestAndChan // written by roundTrip; read by readLoop |
725 writech chan writeRequest // written by roundTrip; read by writeLoop | 728 writech chan writeRequest // written by roundTrip; read by writeLoop |
726 closech chan struct{} // broadcast close when readLoop (TCP conne
ction) closes | 729 closech chan struct{} // broadcast close when readLoop (TCP conne
ction) closes |
727 isProxy bool | 730 isProxy bool |
728 | 731 |
729 lk sync.Mutex // guards following 3 fields | 732 lk sync.Mutex // guards following 3 fields |
730 numExpectedResponses int | 733 numExpectedResponses int |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 if err == nil && resp.StatusCode == 100 { | 788 if err == nil && resp.StatusCode == 100 { |
786 // Skip any 100-continue for now. | 789 // Skip any 100-continue for now. |
787 // TODO(bradfitz): if rc.req had "Expect: 100-co
ntinue", | 790 // TODO(bradfitz): if rc.req had "Expect: 100-co
ntinue", |
788 // actually block the request body write and sig
nal the | 791 // actually block the request body write and sig
nal the |
789 // writeLoop now to begin sending it. (Issue 218
4) For now we | 792 // writeLoop now to begin sending it. (Issue 218
4) For now we |
790 // eat it, since we're never expecting one. | 793 // eat it, since we're never expecting one. |
791 resp, err = ReadResponse(pc.br, rc.req) | 794 resp, err = ReadResponse(pc.br, rc.req) |
792 } | 795 } |
793 } | 796 } |
794 | 797 |
795 » » if tlsConn, ok := pc.conn.(*tls.Conn); resp != nil && ok { | 798 » » if resp != nil { |
796 » » » resp.TLS = new(tls.ConnectionState) | 799 » » » resp.TLS = pc.tlsState |
797 » » » *resp.TLS = tlsConn.ConnectionState() | |
798 } | 800 } |
799 | 801 |
800 hasBody := resp != nil && rc.req.Method != "HEAD" && resp.Conten
tLength != 0 | 802 hasBody := resp != nil && rc.req.Method != "HEAD" && resp.Conten
tLength != 0 |
801 | 803 |
802 if err != nil { | 804 if err != nil { |
803 pc.close() | 805 pc.close() |
804 } else { | 806 } else { |
805 if rc.addedGzip && hasBody && resp.Header.Get("Content-E
ncoding") == "gzip" { | 807 if rc.addedGzip && hasBody && resp.Header.Get("Content-E
ncoding") == "gzip" { |
806 resp.Header.Del("Content-Encoding") | 808 resp.Header.Del("Content-Encoding") |
807 resp.Header.Del("Content-Length") | 809 resp.Header.Del("Content-Length") |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 type readerAndCloser struct { | 1127 type readerAndCloser struct { |
1126 io.Reader | 1128 io.Reader |
1127 io.Closer | 1129 io.Closer |
1128 } | 1130 } |
1129 | 1131 |
1130 type tlsHandshakeTimeoutError struct{} | 1132 type tlsHandshakeTimeoutError struct{} |
1131 | 1133 |
1132 func (tlsHandshakeTimeoutError) Timeout() bool { return true } | 1134 func (tlsHandshakeTimeoutError) Timeout() bool { return true } |
1133 func (tlsHandshakeTimeoutError) Temporary() bool { return true } | 1135 func (tlsHandshakeTimeoutError) Temporary() bool { return true } |
1134 func (tlsHandshakeTimeoutError) Error() string { return "net/http: TLS handsha
ke timeout" } | 1136 func (tlsHandshakeTimeoutError) Error() string { return "net/http: TLS handsha
ke timeout" } |
LEFT | RIGHT |