feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -405,6 +406,9 @@ func DoWssRequest(a Adaptor, c *gin.Context, info *common.RelayInfo, requestBody
|
||||
}
|
||||
dialer.Proxy = http.ProxyURL(proxyURL)
|
||||
}
|
||||
if info.ChannelSetting.TLSInsecureSkipVerify {
|
||||
dialer.TLSClientConfig = common2.InsecureTLSConfig
|
||||
}
|
||||
targetConn, resp, err := dialer.DialContext(c.Request.Context(), fullRequestURL, targetHeader)
|
||||
if err != nil {
|
||||
statusCode := http.StatusInternalServerError
|
||||
@@ -499,7 +503,7 @@ func sendPingData(c *gin.Context, mutex *sync.Mutex) error {
|
||||
helper.ExtendWriteDeadline(c)
|
||||
err := helper.PingData(c)
|
||||
if err != nil {
|
||||
logger.LogError(c, "SSE ping error: "+err.Error())
|
||||
logger.LogError(c, common2.LogText("SSE ping error: %s", err.Error()))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -537,13 +541,11 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
relayClient.CheckRedirect = keepUpstreamRedirectResponse
|
||||
if common2.DebugEnabled && req != nil && req.URL != nil {
|
||||
policy := service.NormalizeHTTPTransportPolicy(info.ChannelSetting)
|
||||
logger.LogDebug(c, fmt.Sprintf(
|
||||
"http transport select: host=%s protocol=%s shards=%d policy=%s",
|
||||
logger.LogDebug(c, "http transport select: host=%s protocol=%s shards=%d policy=%s",
|
||||
req.URL.Host,
|
||||
policy.Protocol,
|
||||
policy.Shards,
|
||||
policy.String(),
|
||||
))
|
||||
policy.String())
|
||||
}
|
||||
|
||||
var stopPinger context.CancelFunc
|
||||
@@ -567,11 +569,21 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
}
|
||||
|
||||
info.UpstreamRequests++
|
||||
info.UpstreamTiming = nil
|
||||
if info.UsingGroup == common2.GetEnvOrDefaultString("UPSTREAM_TIMING_GROUP", "") && c.Request.URL.Path == "/v1/responses" {
|
||||
start := c.GetTime("request_received_at")
|
||||
if start.IsZero() {
|
||||
start = info.StartTime
|
||||
}
|
||||
info.UpstreamTiming = common.NewUpstreamTiming(start, info.UpstreamRequests, info.ChannelId, req.ContentLength)
|
||||
}
|
||||
c.Set(common.UpstreamTimingContextKey, info.UpstreamTiming)
|
||||
var guard *common.ResponseGuardAttempt
|
||||
var guardUsage *service.GuardUsageCollector
|
||||
if guardEnabled {
|
||||
var upstream context.Context
|
||||
upstream, guard = info.ResponseGuard.Begin(c.Request.Context(), info.UpstreamRequests, info.ChannelId)
|
||||
guard.Timing = info.UpstreamTiming
|
||||
if info.DurableAttemptID != 0 {
|
||||
guardUsage = service.NewGuardUsageCollector(c, info)
|
||||
guard.OnEvent = guardUsage.Observe
|
||||
@@ -579,6 +591,9 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
}
|
||||
req = req.WithContext(upstream)
|
||||
}
|
||||
if info.UpstreamTiming != nil {
|
||||
req = req.WithContext(httptrace.WithClientTrace(req.Context(), info.UpstreamTiming.ClientTrace()))
|
||||
}
|
||||
resp, err := relayClient.Do(req)
|
||||
if err != nil {
|
||||
if guard != nil {
|
||||
@@ -594,7 +609,7 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
}
|
||||
guard.Reason = "transport_error"
|
||||
}
|
||||
logger.LogError(c, "do request failed: "+err.Error())
|
||||
logger.LogError(c, common2.LogText("do request failed: %s", err.Error()))
|
||||
return nil, types.NewError(err, types.ErrorCodeDoRequestFailed, types.ErrOptionWithHideErrMsg("upstream error: do request failed"))
|
||||
}
|
||||
if resp == nil {
|
||||
@@ -603,6 +618,7 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
}
|
||||
return nil, errors.New("resp is nil")
|
||||
}
|
||||
info.UpstreamTiming.Response(resp.Proto, resp.StatusCode)
|
||||
if guard != nil {
|
||||
if err := guard.Confirm(resp, c.Request.Context()); err != nil {
|
||||
if guardUsage != nil && guardUsage.FinishRejected(info, guard, resp) {
|
||||
@@ -614,17 +630,18 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http
|
||||
guard.Finish(false)
|
||||
return nil, guard.APIError()
|
||||
}
|
||||
if guard.Reason == "accepted" {
|
||||
info.UpstreamTiming.Mark("model_confirmed")
|
||||
}
|
||||
}
|
||||
if common2.DebugEnabled {
|
||||
policy := service.NormalizeHTTPTransportPolicy(info.ChannelSetting)
|
||||
logger.LogDebug(c, fmt.Sprintf(
|
||||
"http transport negotiated: host=%s protocol=%s shards=%d policy=%s negotiated=%s",
|
||||
logger.LogDebug(c, "http transport negotiated: host=%s protocol=%s shards=%d policy=%s negotiated=%s",
|
||||
req.URL.Host,
|
||||
policy.Protocol,
|
||||
policy.Shards,
|
||||
policy.String(),
|
||||
resp.Proto,
|
||||
))
|
||||
resp.Proto)
|
||||
}
|
||||
|
||||
if upID := resp.Header.Get(common2.RequestIdKey); upID != "" {
|
||||
|
||||
Reference in new issue
Block a user