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

feat (request): expose req timeout #1878

Merged
Merged
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
10 changes: 10 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ func (req *Request) SetConnectionClose() {
req.Header.SetConnectionClose()
}

// GetTimeOut retrieves the timeout duration set for the Request.
//
// This method returns a time.Duration that determines how long the request
// can wait before it times out. In the default use case, the timeout applies
// to the entire request lifecycle, including both receiving the response
// headers and the response body.
func (req *Request) GetTimeOut() time.Duration {
return req.timeout
}

// SendFile registers file on the given path to be used as response body
// when Write is called.
//
Expand Down
23 changes: 23 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3174,3 +3174,26 @@ func TestRespCopeToRace(t *testing.T) {
}
}
}

func TestRequestGetTimeOut(t *testing.T) {
tests := []struct {
name string
timeout time.Duration
expected time.Duration
}{
{"Timeout set to 0", 0, 0},
{"Timeout set to 5s", 5 * time.Second, 5 * time.Second},
{"Timeout set to 1m", 1 * time.Minute, 1 * time.Minute},
{"Timeout set to 500ms", 500 * time.Millisecond, 500 * time.Millisecond},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
req := &Request{timeout: test.timeout}

if got := req.GetTimeOut(); got != test.expected {
t.Errorf("GetTimeOut() = %v, want %v", got, test.expected)
}
})
}
}