chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package rerank
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
secutils "academy/internal/utils"
|
||||
)
|
||||
|
||||
func validateRerankBaseURL(baseURL string) error {
|
||||
if baseURL == "" {
|
||||
return nil
|
||||
}
|
||||
if err := secutils.ValidateURLForSSRF(baseURL); err != nil {
|
||||
return fmt.Errorf("base URL SSRF check failed: %w", err)
|
||||
}
|
||||
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(),
|
||||
)
|
||||
|
||||
// defaultRerankRequestTimeout caps one rerank request when the catalog sets
|
||||
// no timeout. Chat and agent contexts carry no deadline of their own, so a
|
||||
// stalled self-hosted rerank server used to hold the turn open until the
|
||||
// client disconnected. A failed call degrades to retrieval order.
|
||||
const defaultRerankRequestTimeout = 60 * time.Second
|
||||
|
||||
// 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 {
|
||||
if timeout <= 0 {
|
||||
timeout = defaultRerankRequestTimeout
|
||||
}
|
||||
cfg := secutils.DefaultSSRFSafeHTTPClientConfig()
|
||||
cfg.Timeout = timeout
|
||||
return secutils.NewSSRFSafeHTTPClientWithTransport(cfg, sharedRerankHTTPTransport)
|
||||
}
|
||||
Reference in new issue
Block a user