Skip to content

Commit

Permalink
Enable per-request timeout for POSTs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jul 27, 2024
1 parent 166b693 commit 22abb36
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io
func (s *Service) post2(ctx context.Context,
endpoint string,
query string,
_ *api.CommonOpts,
opts *api.CommonOpts,
body io.Reader,
contentType ContentType,
headers map[string]string,
Expand Down Expand Up @@ -151,7 +151,12 @@ func (s *Service) post2(ctx context.Context,
log.Trace().Str("url", callURL.String()).Msg("URL to POST")
span.SetAttributes(attribute.String("url", callURL.String()))

opCtx, cancel := context.WithTimeout(ctx, s.timeout)
timeout := s.timeout
if opts.Timeout != 0 {
timeout = opts.Timeout
}

opCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
req, err := http.NewRequestWithContext(opCtx, http.MethodPost, callURL.String(), body)
if err != nil {
Expand Down

0 comments on commit 22abb36

Please sign in to comment.