Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1125)

Delta Between Two Patch Sets: src/pkg/net/http/transport_test.go

Issue 137940043: code review 137940043: net/http: add Transport.DialTLS hook (Closed)
Left Patch Set: diff -r c9c8b336ffcc2f515d2693f681852fcf598fbca4 https://go.googlecode.com/hg/ Created 9 years, 6 months ago
Right Patch Set: diff -r 0a5fafdd2343b083457d0baf6487dfce0f01e25f https://go.googlecode.com/hg/ Created 9 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/http/transport.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(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 // Tests for transport.go 5 // Tests for transport.go
6 6
7 package http_test 7 package http_test
8 8
9 import ( 9 import (
10 "bufio" 10 "bufio"
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 if err == nil { 2086 if err == nil {
2087 t.Errorf("Unexpected success reading request body from h andler; want 'unexpected EOF reading trailer'") 2087 t.Errorf("Unexpected success reading request body from h andler; want 'unexpected EOF reading trailer'")
2088 } 2088 }
2089 case <-time.After(5 * time.Second): 2089 case <-time.After(5 * time.Second):
2090 t.Error("timeout waiting for server handler to complete") 2090 t.Error("timeout waiting for server handler to complete")
2091 } 2091 }
2092 select { 2092 select {
2093 case <-didClose: 2093 case <-didClose:
2094 default: 2094 default:
2095 t.Errorf("didn't see Body.Close") 2095 t.Errorf("didn't see Body.Close")
2096 }
2097 }
2098
2099 func TestTransportDialTLS(t *testing.T) {
2100 var mu sync.Mutex // guards following
2101 var gotReq, didDial bool
2102
2103 ts := httptest.NewTLSServer(HandlerFunc(func(w ResponseWriter, r *Reques t) {
2104 mu.Lock()
2105 gotReq = true
2106 mu.Unlock()
2107 }))
2108 defer ts.Close()
2109 tr := &Transport{
2110 DialTLS: func(netw, addr string) (net.Conn, error) {
2111 mu.Lock()
2112 didDial = true
2113 mu.Unlock()
2114 c, err := tls.Dial(netw, addr, &tls.Config{
2115 InsecureSkipVerify: true,
2116 })
2117 if err != nil {
2118 return nil, err
2119 }
2120 return c, c.Handshake()
2121 },
2122 }
2123 defer tr.CloseIdleConnections()
2124 client := &Client{Transport: tr}
2125 res, err := client.Get(ts.URL)
2126 if err != nil {
2127 t.Fatal(err)
2128 }
2129 res.Body.Close()
2130 mu.Lock()
2131 if !gotReq {
2132 t.Error("didn't get request")
2133 }
2134 if !didDial {
2135 t.Error("didn't use dial hook")
2096 } 2136 }
2097 } 2137 }
2098 2138
2099 func wantBody(res *http.Response, err error, want string) error { 2139 func wantBody(res *http.Response, err error, want string) error {
2100 if err != nil { 2140 if err != nil {
2101 return err 2141 return err
2102 } 2142 }
2103 slurp, err := ioutil.ReadAll(res.Body) 2143 slurp, err := ioutil.ReadAll(res.Body)
2104 if err != nil { 2144 if err != nil {
2105 return fmt.Errorf("error reading body: %v", err) 2145 return fmt.Errorf("error reading body: %v", err)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 2202 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
2163 0x17, 0x00, 0xe8, 0xff, 0x42, 0x12, 0x46, 0x16, 2203 0x17, 0x00, 0xe8, 0xff, 0x42, 0x12, 0x46, 0x16,
2164 0x06, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, 2204 0x06, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08,
2165 0x00, 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 2205 0x00, 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa,
2166 0x00, 0x00, 0x00, 0x42, 0x12, 0x46, 0x16, 0x06, 2206 0x00, 0x00, 0x00, 0x42, 0x12, 0x46, 0x16, 0x06,
2167 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, 0x00, 2207 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, 0x00,
2168 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, 2208 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00,
2169 0x00, 0x00, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, 2209 0x00, 0x00, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00,
2170 0x00, 0x00, 2210 0x00, 0x00,
2171 } 2211 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b