Skip to content

Commit

Permalink
Fix supported formats fetching timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
4ernovm committed Dec 1, 2023
1 parent 155b214 commit f7a8b51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions internal/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func get(uri string, debClient *DebClient, retry bool, format string) (*http.Res
if err != nil {
return nil, err
}

if debClient.timeout > 0 {
timeoutDuration := time.Duration(debClient.timeout) * time.Second
ctx, cancel := context.WithTimeout(request.Context(), timeoutDuration)
defer cancel()
request = request.WithContext(ctx)
}

res, _ := debClient.httpClient.Do(request)
req := func() (*http.Response, error) {
return get(uri, debClient, false, format)
Expand All @@ -37,13 +45,6 @@ func post(uri string, debClient *DebClient, contentType string, body *bytes.Buff
}
request.Header.Add("Content-Type", contentType)

if debClient.timeout > 0 {
timeoutDuration := time.Duration(debClient.timeout) * time.Second
ctx, cancel := context.WithTimeout(request.Context(), timeoutDuration)
defer cancel()
request = request.WithContext(ctx)
}

res, err := debClient.httpClient.Do(request)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/file/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (finder *Finder) GetSupportedFormats() ([]*CompiledFormat, error) {
}

func (finder *Finder) GetSupportedFormatsJson() ([]byte, error) {
finder.debClient.ConfigureClientSettings(false, 5)
finder.debClient.ConfigureClientSettings(false, 3)
defer finder.debClient.ConfigureClientSettings(true, 15)

res, err := finder.debClient.Get(SupportedFormatsUri, "application/json")
Expand Down

0 comments on commit f7a8b51

Please sign in to comment.