-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreply.go
executable file
·47 lines (44 loc) · 1.06 KB
/
reply.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
package minigrush
import (
"io/ioutil"
"net/http"
"time"
)
//Reply represents the response from the target host
type Reply struct {
//Reply id. Currently the same as the petition id
Id string
//Possible error in making the request. Could be ""
Error string
StatusCode int // e.g. 200
Proto string // e.g. "HTTP/1.0"
Header http.Header
Trailer http.Header
Body []byte
//Petition that
Petition *Petition
//Beginning of the request
Created time.Time
//Time when response was received
Done time.Time
}
//newReply returns the Reply for the Petition made, the http.Response got and the possible error
func newReply(resp *http.Response, p *Petition, e error) *Reply {
var reply = &Reply{Id: p.Id, Petition: p}
if e != nil {
reply.Error = e.Error()
return reply
}
reply.StatusCode = resp.StatusCode
reply.Proto = resp.Proto
reply.Header = resp.Header
reply.Trailer = resp.Trailer
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
reply.Error = e.Error()
} else {
reply.Body = body
}
reply.Done = time.Now()
return reply
}