refactor(http): share SSRF-safe transport across model clients
Extract NewSSRFSafeTransport and NewSSRFSafeHTTPClientWithTransport so embedding and rerank can reuse one connection pool without allocating a throwaway transport per client. SSRF dial and redirect policies are unchanged; each client still keeps its own timeout.
This commit is contained in:
@@ -18,8 +18,20 @@ func validateRerankBaseURL(baseURL string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// sharedRerankHTTPTransport keeps a single SSRF-safe connection pool for all
|
||||
// rerank clients. Rerankers are recreated on every GetRerankModel call, but
|
||||
// their outbound connections can be safely reused, so the transport (and its
|
||||
// keep-alive pool) is built once at package load.
|
||||
var sharedRerankHTTPTransport = secutils.NewSSRFSafeTransport(
|
||||
secutils.DefaultSSRFSafeHTTPClientConfig(),
|
||||
)
|
||||
|
||||
// newRerankHTTPClient returns an HTTP client with connection-level SSRF
|
||||
// protection and redirect validation. All clients share
|
||||
// sharedRerankHTTPTransport so keep-alive connections are pooled globally,
|
||||
// while each keeps its own timeout.
|
||||
func newRerankHTTPClient(timeout time.Duration) *http.Client {
|
||||
cfg := secutils.DefaultSSRFSafeHTTPClientConfig()
|
||||
cfg.Timeout = timeout
|
||||
return secutils.NewSSRFSafeHTTPClient(cfg)
|
||||
return secutils.NewSSRFSafeHTTPClientWithTransport(cfg, sharedRerankHTTPTransport)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user