MCPcopy Create free account
hub / github.com/Prejudice-Studio/Twilight / patchJSONWithTimeout

Function patchJSONWithTimeout

internal/api/http_json_client.go:109–123  ·  view source on GitHub ↗
(ctx context.Context, endpoint string, headers map[string]string, body any, dst any, timeout time.Duration)

Source from the content-addressed store, hash-verified

107 Transport: sharedHTTPTransport,
108 CheckRedirect: sameHostRedirectPolicy,
109}
110
111// sameHostRedirectPolicy 只允许同 scheme + 同 host:port 的重定向,且最多 5 跳。
112// 跨主机直接返回 ErrUseLastResponse —— 调用方拿到的是原始 302 响应(结合
113// `resp.StatusCode >= 400` 检查会被当作非预期状态返回错误,不会出现 token
114// 已被发到第三方的窗口)。
115func sameHostRedirectPolicy(req *http.Request, via []*http.Request) error {
116 if len(via) >= 5 {
117 return http.ErrUseLastResponse
118 }
119 if len(via) == 0 {
120 return nil
121 }
122 prev := via[len(via)-1].URL
123 next := req.URL
124 if prev == nil || next == nil {
125 return http.ErrUseLastResponse
126 }

Callers 1

patchJSONFunction · 0.85

Calls 1

doJSONRequestWithTimeoutFunction · 0.85

Tested by

no test coverage detected