mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-10 02:23:43 +08:00
fix: Initialize transport object, set timeouts, and add IdleTimeout config
- Introduced idle connection timeout for HTTP client transport - Implemented custom timeout for HTTP client when `RelayTimeout` is 0 - Set ImpatientHTTPClient timeout to 5 seconds - Added new config variable `IdleTimeout` with default value of 30 seconds - Utilized shared transport object for all HTTP clients in relay/util package
This commit is contained in:
@@ -10,15 +10,24 @@ var HTTPClient *http.Client
|
||||
var ImpatientHTTPClient *http.Client
|
||||
|
||||
func init() {
|
||||
|
||||
tp := &http.Transport{
|
||||
IdleConnTimeout: time.Duration(config.IdleTimeout) * time.Second,
|
||||
}
|
||||
|
||||
if config.RelayTimeout == 0 {
|
||||
HTTPClient = &http.Client{}
|
||||
HTTPClient = &http.Client{
|
||||
Transport: tp,
|
||||
}
|
||||
} else {
|
||||
HTTPClient = &http.Client{
|
||||
Timeout: time.Duration(config.RelayTimeout) * time.Second,
|
||||
Transport: tp,
|
||||
Timeout: time.Duration(config.RelayTimeout) * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
ImpatientHTTPClient = &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
Transport: tp,
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user