mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 01:26:37 +08:00
- 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
34 lines
572 B
Go
34 lines
572 B
Go
package util
|
|
|
|
import (
|
|
"github.com/songquanpeng/one-api/common/config"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
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{
|
|
Transport: tp,
|
|
}
|
|
} else {
|
|
HTTPClient = &http.Client{
|
|
Transport: tp,
|
|
Timeout: time.Duration(config.RelayTimeout) * time.Second,
|
|
}
|
|
}
|
|
|
|
ImpatientHTTPClient = &http.Client{
|
|
Transport: tp,
|
|
Timeout: 5 * time.Second,
|
|
}
|
|
}
|