Use shared HTTP client for upstream requests
- Create package-level httpClient with 300s timeout\n- Reuse client instead of creating new one per request\n- Prevents resource exhaustion under load\n- Reduces connection overhead
This commit is contained in:
parent
b906d49f9e
commit
1c3eccce10
2 changed files with 4 additions and 2 deletions
|
|
@ -19,6 +19,9 @@ type Config struct {
|
|||
|
||||
var config *Config
|
||||
|
||||
// httpClient is a shared HTTP client for all upstream requests
|
||||
var httpClient = &http.Client{Timeout: 300 * time.Second}
|
||||
|
||||
// blockedHeaders are headers that should never be forwarded to upstream
|
||||
// for security/privacy reasons. These headers could leak internal URLs,
|
||||
// session information, or other sensitive data.
|
||||
|
|
@ -218,8 +221,7 @@ func callUpstream(req *AnthropicRequest, apiKey, sessionID string) (*http.Respon
|
|||
httpReq.Header.Set(k, v)
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: 300 * time.Second}
|
||||
return client.Do(httpReq)
|
||||
return httpClient.Do(httpReq)
|
||||
}
|
||||
|
||||
func writeError(w http.ResponseWriter, code int, message, errType, errCode string) {
|
||||
|
|
|
|||
BIN
proxx
BIN
proxx
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue