feat(log): 前后端共用 request_id 与四时间点时钟校准
- X-Request-Id 请求头带合法 UUID 则沿用为 request_id(严格格式白名单防注入),否则自生成 12 位 hex - 响应头新增 X-Server-Received-Ms / X-Server-Sent-Ms 供前端时钟校准 - CORS Allow-Headers 增加 X-Request-Id,Expose-Headers 显式列出(credentials 下不认 *) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -127,6 +128,9 @@ func (that *Context) View() {
|
||||
}
|
||||
that.DataSize = len(d)
|
||||
that.RespData = nil
|
||||
// 服务端发送时间(ms):与 X-Server-Received-Ms 组成四时间点,供前端时钟校准;
|
||||
// 必须在首次 Write 之前设置,否则 header 已锁定
|
||||
that.Resp.Header().Set("X-Server-Sent-Ms", strconv.FormatInt(time.Now().UnixMilli(), 10))
|
||||
that.Resp.Write(d)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user