LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 package httputil | 5 package httputil |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "errors" | 10 "errors" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // with a dummy response. | 95 // with a dummy response. |
96 var buf bytes.Buffer // records the output | 96 var buf bytes.Buffer // records the output |
97 pr, pw := io.Pipe() | 97 pr, pw := io.Pipe() |
98 defer pr.Close() | 98 defer pr.Close() |
99 defer pw.Close() | 99 defer pw.Close() |
100 dr := &delegateReader{c: make(chan io.Reader)} | 100 dr := &delegateReader{c: make(chan io.Reader)} |
101 // Wait for the request before replying with a dummy response: | 101 // Wait for the request before replying with a dummy response: |
102 go func() { | 102 go func() { |
103 req, err := http.ReadRequest(bufio.NewReader(pr)) | 103 req, err := http.ReadRequest(bufio.NewReader(pr)) |
104 if err == nil { | 104 if err == nil { |
105 » » » // Ensure all the body is read otherwise we'll get | 105 » » » // Ensure all the body is read; otherwise |
106 » » » // a partial dump. | 106 » » » // we'll get a partial dump. |
107 io.Copy(ioutil.Discard, req.Body) | 107 io.Copy(ioutil.Discard, req.Body) |
108 req.Body.Close() | 108 req.Body.Close() |
109 } | 109 } |
110 dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\n\r\n") | 110 dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\n\r\n") |
111 }() | 111 }() |
112 | 112 |
113 t := &http.Transport{ | 113 t := &http.Transport{ |
114 DisableKeepAlives: true, | 114 DisableKeepAlives: true, |
115 Dial: func(net, addr string) (net.Conn, error) { | 115 Dial: func(net, addr string) (net.Conn, error) { |
116 return &dumpConn{io.MultiWriter(&buf, pw), dr}, nil | 116 return &dumpConn{io.MultiWriter(&buf, pw), dr}, nil |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if err == errNoBody { | 275 if err == errNoBody { |
276 err = nil | 276 err = nil |
277 } | 277 } |
278 resp.Body = save | 278 resp.Body = save |
279 resp.ContentLength = savecl | 279 resp.ContentLength = savecl |
280 if err != nil { | 280 if err != nil { |
281 return nil, err | 281 return nil, err |
282 } | 282 } |
283 return b.Bytes(), nil | 283 return b.Bytes(), nil |
284 } | 284 } |
LEFT | RIGHT |