Skip to content

Commit

Permalink
chore: refactor gateway http context
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Feb 8, 2025
1 parent e6b4372 commit 8342157
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ func (s *Server) buildHttpHandler(target *HttpClientConf) http.HandlerFunc {
return
}

// accept the context from the original request, including the deadline
req = req.WithContext(r.Context())
// set the timeout if it's configured, take effect only if it's greater than 0
// and less than the deadline of the original request
if target.Timeout > 0 {
timeout := time.Duration(target.Timeout) * time.Millisecond
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()
req = req.WithContext(ctx)
} else {
req = req.WithContext(r.Context())
}

resp, err := httpc.DoRequest(req)
Expand Down

0 comments on commit 8342157

Please sign in to comment.