-
Notifications
You must be signed in to change notification settings - Fork 1
/
response.go
52 lines (43 loc) · 1.23 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
package http
import (
"net/http"
)
// HttpResponse is a simple wrapper of "net/http" response
type HttpResponse struct {
body []byte
statusCode int
originHttpResponse *http.Response // origin "net/http" response
}
// NewHttpResponse will create a new response of http request
func NewHttpResponse() *HttpResponse {
return &HttpResponse{}
}
// GetBody will get body from from sdk http request
func (h *HttpResponse) GetBody() []byte {
return h.body
}
func (h *HttpResponse) GetHeaders() http.Header {
if h.originHttpResponse == nil {
return http.Header{}
}
return h.originHttpResponse.Header
}
// SetBody will set body into http response
// it usually used for restore the body already read from an stream
// it will also cause extra memory usage
func (h *HttpResponse) SetBody(body []byte) error {
h.body = body
return nil
}
// GetStatusCode will return status code of origin http response
func (h *HttpResponse) GetStatusCode() int {
return h.statusCode
}
// SetStatusCode will return status code of origin http response
func (h *HttpResponse) SetStatusCode(code int) {
h.statusCode = code
}
func (h *HttpResponse) setHttpResponse(resp *http.Response) {
h.statusCode = resp.StatusCode
h.originHttpResponse = resp
}