Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add duration field to the response #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ func (r RawRequest) GetTimeout() time.Duration {
func Do(req Requester) (*Response, error) {
var conn io.ReadWriter
var connerr error
var start time.Time
var duration time.Duration
var response *Response

start = time.Now()

// This needs timeouts because it's fairly likely
// that something will go wrong :)
Expand All @@ -302,12 +307,17 @@ func Do(req Requester) (*Response, error) {
conn, connerr = d.Dial("tcp", req.Host())
}

duration = time.Since(start)

if connerr != nil {
return nil, connerr
}

fmt.Fprint(conn, req.String())
fmt.Fprint(conn, "\r\n")

return newResponse(conn)
response, err := newResponse(conn)
response.Duration = duration

return response, err
}
2 changes: 2 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"io/ioutil"
"strconv"
"strings"
"time"
)

// A Response wraps the HTTP response from the server
type Response struct {
rawStatus string
headers []string
body []byte
Duration time.Duration
}

// Header finds and returns the value of a header on the response.
Expand Down