mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 20:22:20 +08:00
perf: use textproto.TrimString for HTTP header parsing to improve performance
This commit is contained in:
parent
e4c2a27624
commit
7303932ab2
3
gin.go
3
gin.go
@ -9,6 +9,7 @@ import (
|
||||
"html/template"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
@ -475,7 +476,7 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
|
||||
}
|
||||
items := strings.Split(header, ",")
|
||||
for i := len(items) - 1; i >= 0; i-- {
|
||||
ipStr := strings.TrimSpace(items[i])
|
||||
ipStr := textproto.TrimString(items[i])
|
||||
ip := net.ParseIP(ipStr)
|
||||
if ip == nil {
|
||||
break
|
||||
|
3
utils.go
3
utils.go
@ -7,6 +7,7 @@ package gin
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
@ -107,7 +108,7 @@ func parseAccept(acceptHeader string) []string {
|
||||
if i := strings.IndexByte(part, ';'); i > 0 {
|
||||
part = part[:i]
|
||||
}
|
||||
if part = strings.TrimSpace(part); part != "" {
|
||||
if part = textproto.TrimString(part); part != "" {
|
||||
out = append(out, part)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user