mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-09 02:03:42 +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:
@@ -110,6 +110,7 @@ var BatchUpdateEnabled = false
|
|||||||
var BatchUpdateInterval = helper.GetOrDefaultEnvInt("BATCH_UPDATE_INTERVAL", 5)
|
var BatchUpdateInterval = helper.GetOrDefaultEnvInt("BATCH_UPDATE_INTERVAL", 5)
|
||||||
|
|
||||||
var RelayTimeout = helper.GetOrDefaultEnvInt("RELAY_TIMEOUT", 0) // unit is second
|
var RelayTimeout = helper.GetOrDefaultEnvInt("RELAY_TIMEOUT", 0) // unit is second
|
||||||
|
var IdleTimeout = helper.GetOrDefaultEnvInt("IDLE_TIMEOUT", 30) // unit is second
|
||||||
|
|
||||||
var GeminiSafetySetting = helper.GetOrDefaultEnvString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
var GeminiSafetySetting = helper.GetOrDefaultEnvString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,24 @@ var HTTPClient *http.Client
|
|||||||
var ImpatientHTTPClient *http.Client
|
var ImpatientHTTPClient *http.Client
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
|
tp := &http.Transport{
|
||||||
|
IdleConnTimeout: time.Duration(config.IdleTimeout) * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
if config.RelayTimeout == 0 {
|
if config.RelayTimeout == 0 {
|
||||||
HTTPClient = &http.Client{}
|
HTTPClient = &http.Client{
|
||||||
|
Transport: tp,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HTTPClient = &http.Client{
|
HTTPClient = &http.Client{
|
||||||
Timeout: time.Duration(config.RelayTimeout) * time.Second,
|
Transport: tp,
|
||||||
|
Timeout: time.Duration(config.RelayTimeout) * time.Second,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImpatientHTTPClient = &http.Client{
|
ImpatientHTTPClient = &http.Client{
|
||||||
Timeout: 5 * time.Second,
|
Transport: tp,
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user