diff --git a/internal/server/router/router.go b/internal/server/router/router.go index 8e12bd7..efeec7d 100644 --- a/internal/server/router/router.go +++ b/internal/server/router/router.go @@ -4,6 +4,7 @@ import ( errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/gateway" "ai_scheduler/internal/services" + "bytes" "encoding/json" "fmt" "io" @@ -158,11 +159,14 @@ func forwardToPythonService(c *fiber.Ctx) error { } func forwardScbankQualification(c *fiber.Ctx) error { + requestBody := c.Body() + requestQuery := c.Context().QueryArgs().String() + // 调用外部权益接口前记录目标地址与关键请求信息,便于排查白名单和超时问题。 startAt := time.Now() - log.Printf("开始转发权益校验请求 | method=%s | path=%s | target=%s", c.Method(), c.Path(), scbankQualificationProxyURL) + log.Printf("开始转发权益校验请求 | method=%s | path=%s | target=%s | query=%s | headers=%s | body=%s", c.Method(), c.Path(), scbankQualificationProxyURL, requestQuery, formatHeaders(c.GetReqHeaders()), string(requestBody)) - req, err := http.NewRequestWithContext(c.Context(), c.Method(), scbankQualificationProxyURL, c.Context().Request.BodyStream()) + req, err := http.NewRequestWithContext(c.Context(), c.Method(), scbankQualificationProxyURL, bytes.NewReader(requestBody)) if err != nil { log.Printf("创建权益中转请求失败 | target=%s | err=%v", scbankQualificationProxyURL, err) return c.Status(fiber.StatusInternalServerError).SendString(err.Error()) @@ -200,11 +204,22 @@ func forwardScbankQualification(c *fiber.Ctx) error { return c.Status(fiber.StatusInternalServerError).SendString(err.Error()) } - log.Printf("权益中转请求完成 | target=%s | status=%d | cost=%s", scbankQualificationProxyURL, resp.StatusCode, time.Since(startAt)) + log.Printf("权益中转请求完成 | target=%s | status=%d | cost=%s | headers=%s | body=%s", scbankQualificationProxyURL, resp.StatusCode, time.Since(startAt), formatHeaders(resp.Header), string(body)) c.Status(resp.StatusCode) return c.Send(body) } +func formatHeaders(headers map[string][]string) string { + if len(headers) == 0 { + return "{}" + } + data, err := json.Marshal(headers) + if err != nil { + return "{}" + } + return string(data) +} + func routerSocket(app *fiber.App, chatService *services.ChatService) { ws := app.Group("ws/v1/") // WebSocket 路由配置