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 // The httptest package provides utilities for HTTP testing. | 5 // The httptest package provides utilities for HTTP testing. |
6 package httptest | 6 package httptest |
7 | 7 |
8 import ( | 8 import ( |
9 "bufio" | |
10 "bytes" | 9 "bytes" |
11 "http" | 10 "http" |
12 "io" | |
13 "os" | 11 "os" |
14 ) | 12 ) |
15 | 13 |
16 // ResponseRecorder is an implementation of http.ResponseWriter that | 14 // ResponseRecorder is an implementation of http.ResponseWriter that |
17 // records its mutations for later inspection in tests. | 15 // records its mutations for later inspection in tests. |
18 // | |
19 // Note that Hijack is not implemented and simply panics. | |
20 type ResponseRecorder struct { | 16 type ResponseRecorder struct { |
21 Code int // the HTTP response code from WriteHeader | 17 Code int // the HTTP response code from WriteHeader |
22 Header http.Header // if non-nil, the headers to populate | 18 Header http.Header // if non-nil, the headers to populate |
23 Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written
data to | 19 Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written
data to |
24 Flushed bool | 20 Flushed bool |
25 | 21 |
26 FakeRemoteAddr string // the fake RemoteAddr to return, or "" for Defaul
tRemoteAddr | 22 FakeRemoteAddr string // the fake RemoteAddr to return, or "" for Defaul
tRemoteAddr |
27 FakeUsingTLS bool // whether to return true from the UsingTLS method | 23 FakeUsingTLS bool // whether to return true from the UsingTLS method |
28 } | 24 } |
29 | 25 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 70 |
75 // WriteHeader sets rw.Code. | 71 // WriteHeader sets rw.Code. |
76 func (rw *ResponseRecorder) WriteHeader(code int) { | 72 func (rw *ResponseRecorder) WriteHeader(code int) { |
77 rw.Code = code | 73 rw.Code = code |
78 } | 74 } |
79 | 75 |
80 // Flush sets rw.Flushed to true. | 76 // Flush sets rw.Flushed to true. |
81 func (rw *ResponseRecorder) Flush() { | 77 func (rw *ResponseRecorder) Flush() { |
82 rw.Flushed = true | 78 rw.Flushed = true |
83 } | 79 } |
84 | |
85 // Hijack is not implemented in ResponseRecorder and instead panics. | |
86 func (rw *ResponseRecorder) Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.
Error) { | |
87 panic("Hijack not implemented in ResponseRecorder") | |
88 } | |
LEFT | RIGHT |