-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_response.go
73 lines (60 loc) · 2.1 KB
/
http_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
package golden
import (
"github.com/go-resty/resty/v2"
"net/http"
"time"
)
type HttpResponse struct {
impl *resty.Response
}
// Body method returns HTTP response as []byte array for the executed request.
// Note: `Response.Body` might be nil, if `Request.SetOutput` is used.
func (r *HttpResponse) Body() []byte {
return r.impl.Body()
}
// Status method returns the HTTP status string for the executed request.
// Example: 200 OK
func (r *HttpResponse) Status() string {
return r.impl.Status()
}
// StatusCode method returns the HTTP status code for the executed request.
// Example: 200
func (r *HttpResponse) StatusCode() int {
return r.impl.StatusCode()
}
// Result method returns the response value as an object if it has one
func (r *HttpResponse) Result() interface{} {
return r.impl.Result()
}
// Error method returns the error object if it has one
func (r *HttpResponse) Error() interface{} {
return r.impl.Error()
}
// Header method returns the response headers
func (r *HttpResponse) Header() http.Header {
return r.impl.Header()
}
// Cookies method to access all the response cookies
func (r *HttpResponse) Cookies() []*http.Cookie {
return r.impl.Cookies()
}
// String method returns the body of the server response as String.
func (r *HttpResponse) String() string {
return r.impl.String()
}
// Time method returns the time of HTTP response time that from request we sent and received a request.
// See `response.ReceivedAt` to know when client recevied response and see `response.Request.Time` to know
// when client sent a request.
func (r *HttpResponse) Time() time.Duration {
return r.impl.Time()
}
// ReceivedAt method returns when response got recevied from server for the request.
func (r *HttpResponse) ReceivedAt() time.Time {
return r.impl.ReceivedAt()
}
// Size method returns the HTTP response size in bytes. Ya, you can relay on HTTP `Content-Length` header,
// however it won't be good for chucked transfer/compressed response. Since Resty calculates response size
// at the client end. You will get actual size of the http response.
func (r *HttpResponse) Size() int64 {
return r.impl.Size()
}