OLD | NEW |
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 "fmt" | 10 "fmt" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 pr, pw := io.Pipe() | 82 pr, pw := io.Pipe() |
83 dr := &delegateReader{c: make(chan io.Reader)} | 83 dr := &delegateReader{c: make(chan io.Reader)} |
84 // Wait for the request before replying with a dummy response: | 84 // Wait for the request before replying with a dummy response: |
85 go func() { | 85 go func() { |
86 http.ReadRequest(bufio.NewReader(pr)) | 86 http.ReadRequest(bufio.NewReader(pr)) |
87 dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\n\r\n") | 87 dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\n\r\n") |
88 }() | 88 }() |
89 | 89 |
90 t := &http.Transport{ | 90 t := &http.Transport{ |
91 Dial: func(net, addr string) (net.Conn, error) { | 91 Dial: func(net, addr string) (net.Conn, error) { |
92 » » » return &dumpConn{io.MultiWriter(pw, &buf), dr}, nil | 92 » » » return &dumpConn{io.MultiWriter(&buf, pw), dr}, nil |
93 }, | 93 }, |
94 } | 94 } |
95 | 95 |
96 _, err := t.RoundTrip(reqSend) | 96 _, err := t.RoundTrip(reqSend) |
97 | 97 |
98 req.Body = save | 98 req.Body = save |
99 if err != nil { | 99 if err != nil { |
100 return nil, err | 100 return nil, err |
101 } | 101 } |
102 return buf.Bytes(), nil | 102 return buf.Bytes(), nil |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 220 } |
221 err = resp.Write(&b) | 221 err = resp.Write(&b) |
222 resp.Body = save | 222 resp.Body = save |
223 resp.ContentLength = savecl | 223 resp.ContentLength = savecl |
224 if err != nil { | 224 if err != nil { |
225 return | 225 return |
226 } | 226 } |
227 dump = b.Bytes() | 227 dump = b.Bytes() |
228 return | 228 return |
229 } | 229 } |
OLD | NEW |