Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commitc2de7b2

Browse files
committed
[release-branch.go1] net/http: add missing hasToken function
1 parent6ab2bfa commitc2de7b2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎src/pkg/net/http/header.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,43 @@ func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error {
7676
// the rest are converted to lowercase. For example, the
7777
// canonical key for "accept-encoding" is "Accept-Encoding".
7878
funcCanonicalHeaderKey(sstring)string {returntextproto.CanonicalMIMEHeaderKey(s) }
79+
80+
// hasToken returns whether token appears with v, ASCII
81+
// case-insensitive, with space or comma boundaries.
82+
// token must be all lowercase.
83+
// v may contain mixed cased.
84+
funchasToken(v,tokenstring)bool {
85+
iflen(token)>len(v)||token=="" {
86+
returnfalse
87+
}
88+
ifv==token {
89+
returntrue
90+
}
91+
forsp:=0;sp<=len(v)-len(token);sp++ {
92+
// Check that first character is good.
93+
// The token is ASCII, so checking only a single byte
94+
// is sufficient. We skip this potential starting
95+
// position if both the first byte and its potential
96+
// ASCII uppercase equivalent (b|0x20) don't match.
97+
// False positives ('^' => '~') are caught by EqualFold.
98+
ifb:=v[sp];b!=token[0]&&b|0x20!=token[0] {
99+
continue
100+
}
101+
// Check that start pos is on a valid token boundary.
102+
ifsp>0&&!isTokenBoundary(v[sp-1]) {
103+
continue
104+
}
105+
// Check that end pos is on a valid token boundary.
106+
ifendPos:=sp+len(token);endPos!=len(v)&&!isTokenBoundary(v[endPos]) {
107+
continue
108+
}
109+
ifstrings.EqualFold(v[sp:sp+len(token)],token) {
110+
returntrue
111+
}
112+
}
113+
returnfalse
114+
}
115+
116+
funcisTokenBoundary(bbyte)bool {
117+
returnb==' '||b==','||b=='\t'
118+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp