-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathstrings.go
More file actions
97 lines (82 loc) · 2.41 KB
/
Copy pathstrings.go
File metadata and controls
97 lines (82 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package http2
import (
"bytes"
"errors"
)
var (
StringPath = []byte(":path")
StringStatus = []byte(":status")
StringAuthority = []byte(":authority")
StringScheme = []byte(":scheme")
StringMethod = []byte(":method")
StringServer = []byte("server")
StringContentLength = []byte("content-length")
StringContentType = []byte("content-type")
StringUserAgent = []byte("user-agent")
StringGzip = []byte("gzip")
StringGET = []byte("GET")
StringHEAD = []byte("HEAD")
StringPOST = []byte("POST")
StringHTTP2 = []byte("HTTP/2")
// Connection-specific header fields that are forbidden in HTTP/2.
// https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.2
StringConnection = []byte("connection")
StringKeepAlive = []byte("keep-alive")
StringProxyConnection = []byte("proxy-connection")
StringTransferEncoding = []byte("transfer-encoding")
StringUpgrade = []byte("upgrade")
StringTE = []byte("te")
StringTrailers = []byte("trailers")
)
// hasUpperCase reports whether b contains an uppercase ASCII letter.
// HTTP/2 header field names must be lowercase.
// https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2
func hasUpperCase(b []byte) bool {
for _, c := range b {
if c >= 'A' && c <= 'Z' {
return true
}
}
return false
}
// parseUint parses a non-negative base-10 integer from b. It errors on empty
// input or any non-digit byte.
func parseUint(b []byte) (int, error) {
if len(b) == 0 {
return 0, errInvalidUint
}
n := 0
for _, c := range b {
if c < '0' || c > '9' {
return 0, errInvalidUint
}
n = n*10 + int(c-'0')
}
return n, nil
}
var errInvalidUint = errors.New("invalid unsigned integer")
// isConnectionSpecific reports whether the (lowercase) header name is a
// connection-specific field forbidden in HTTP/2.
func isConnectionSpecific(k []byte) bool {
switch {
case bytes.Equal(k, StringConnection),
bytes.Equal(k, StringKeepAlive),
bytes.Equal(k, StringProxyConnection),
bytes.Equal(k, StringTransferEncoding),
bytes.Equal(k, StringUpgrade):
return true
}
return false
}
func ToLower(b []byte) []byte {
for i := range b {
b[i] |= 32
}
return b
}
const (
// H2TLSProto is the string used in ALPN-TLS negotiation.
H2TLSProto = "h2"
// H2Clean is the string used in HTTP headers by the client to upgrade the connection.
H2Clean = "h2c"
)