Skip to content

Commit

Permalink
Merge pull request #24 from microsoft/feat/add-request-timeout
Browse files Browse the repository at this point in the history
Adds a default 100 secs timeout per request
  • Loading branch information
baywet committed Aug 30, 2022
2 parents f60b70e + 790adbd commit 7f2b427
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 7f2b427

Please sign in to comment.