-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_recorder.go
46 lines (36 loc) · 927 Bytes
/
response_recorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package httpcache
import (
"bytes"
"net/http"
"net/http/httptest"
)
type ResponseRecorder interface {
http.ResponseWriter
Body() *bytes.Buffer
Code() int
Result() *http.Response
}
type recordedResponseWriter struct {
r *httptest.ResponseRecorder
}
func (crw *recordedResponseWriter) WriteHeader(statusCode int) {
crw.r.WriteHeader(statusCode)
}
func (crw *recordedResponseWriter) Write(b []byte) (int, error) {
return crw.r.Write(b)
}
func (crw *recordedResponseWriter) Header() http.Header {
return crw.r.Header()
}
func (crw *recordedResponseWriter) Body() *bytes.Buffer {
return crw.r.Body
}
func (crw *recordedResponseWriter) Code() int {
return crw.r.Code
}
func (crw *recordedResponseWriter) Result() *http.Response {
return crw.r.Result()
}
func NewResponseRecorder() ResponseRecorder {
return &recordedResponseWriter{r:httptest.NewRecorder()}
}