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

Adds a default 100 secs timeout per request #24

Merged
merged 2 commits into from Aug 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.6.2] - 2022-08-30

### Added

- Default 100 secs timeout for all request with a default context.

## [0.6.1] - 2022-08-29

### Changed
Expand Down
10 changes: 9 additions & 1 deletion nethttp_request_adapter.go
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

ctx "context"
nethttp "net/http"
Expand Down Expand Up @@ -149,12 +150,19 @@ func (a *NetHttpRequestAdapter) getResponsePrimaryContentType(response *nethttp.
func (a *NetHttpRequestAdapter) setBaseUrlForRequestInformation(requestInfo *abs.RequestInformation) {
requestInfo.PathParameters["baseurl"] = a.GetBaseUrl()
}

const requestTimeOutInSeconds = 100

func (a *NetHttpRequestAdapter) getRequestFromRequestInformation(requestInfo *abs.RequestInformation) (*nethttp.Request, error) {
uri, err := requestInfo.GetUri()
if err != nil {
return nil, err
}
request, err := nethttp.NewRequest(requestInfo.Method.String(), uri.String(), nil)

context, cancel := ctx.WithTimeout(ctx.Background(), time.Second*requestTimeOutInSeconds)
defer cancel()

request, err := nethttp.NewRequestWithContext(context, requestInfo.Method.String(), uri.String(), nil)
if err != nil {
return nil, err
}
Expand Down