-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
78 lines (64 loc) · 1.44 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package idemgotent
import "net/http"
type (
serializableResponse struct {
_msgpack struct{} `msgpack:",omitempty"`
StatusCode int
Header http.Header
Body []byte
// Unserializable fields.
//
// Allows serialization only on the required fields
// but still have access to the data on return.
pStatusCode int
pHeader http.Header
pBody []byte
}
CapturedResponse interface {
// Obtain the captured status code from the response.
GetStatusCode() int
// Obtain the captured header from the response.
GetHeader() http.Header
// Obtain the captured body from the response.
GetBody() []byte
}
)
func (sr *serializableResponse) setStatusCode(statusCode int, serialize bool) {
if serialize {
sr.StatusCode = statusCode
return
}
sr.pStatusCode = statusCode
}
func (sr *serializableResponse) setHeader(header http.Header, serialize bool) {
if serialize {
sr.Header = header
return
}
sr.pHeader = header
}
func (sr *serializableResponse) setBody(body []byte, serialize bool) {
if serialize {
sr.Body = body
return
}
sr.pBody = body
}
func (sr serializableResponse) GetStatusCode() int {
if sr.StatusCode != 0 {
return sr.StatusCode
}
return sr.pStatusCode
}
func (sr serializableResponse) GetHeader() http.Header {
if sr.Header != nil {
return sr.Header
}
return sr.pHeader
}
func (sr serializableResponse) GetBody() []byte {
if sr.Body != nil {
return sr.Body
}
return sr.pBody
}