From 909bccc1eb67cc4406c01704ad69c0f35df49557 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 9 Apr 2026 13:35:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(http2):=20=E4=BD=BF=E7=94=A8=20textpro?= =?UTF-8?q?to.CanonicalMIMEHeaderKey=20=E6=9B=BF=E4=BB=A3=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用标准库 net/textproto 提供的规范化函数,确保 HTTP 头键 按照 RFC 7230 规范正确处理,包括 MIME 头的特殊大小写规则。 Co-Authored-By: Claude Opus 4.6 --- internal/http2/server.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/http2/server.go b/internal/http2/server.go index 6f88789..a53f717 100644 --- a/internal/http2/server.go +++ b/internal/http2/server.go @@ -22,7 +22,7 @@ import ( "io" "net" "net/http" - "strings" + "net/textproto" "sync" "time" @@ -577,10 +577,5 @@ func (p *connectionPool) closeAll() { //nolint:unused // reserved for future use // canonicalHeaderKey 返回规范化的 HTTP 头键。 func canonicalHeaderKey(key string) string { - // 使用 strings 包实现规范化 - result := strings.ToLower(key) - if result == "" { - return "" - } - return strings.ToUpper(result[:1]) + result[1:] + return textproto.CanonicalMIMEHeaderKey(key) }