forked from ComboStrikeHQ/vcr-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
response.go
43 lines (38 loc) · 888 Bytes
/
response.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
package httpvcr
import (
"bytes"
"io/ioutil"
"net/http"
)
type VCRResponse struct {
Status string
StatusCode int
ContentLength int64
Header http.Header
Body []byte
}
func newVCRResponse(response *http.Response) *VCRResponse {
var body []byte
if response.Body != nil {
body, _ = ioutil.ReadAll(response.Body)
}
return &VCRResponse{
Status: response.Status,
StatusCode: response.StatusCode,
Header: response.Header,
ContentLength: response.ContentLength,
Body: body,
}
}
func (vr *VCRResponse) httpResponse() *http.Response {
return &http.Response{
Status: vr.Status,
StatusCode: vr.StatusCode,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Header: vr.Header,
ContentLength: vr.ContentLength,
Body: ioutil.NopCloser(bytes.NewBuffer(vr.Body)),
}
}