Skip to content

Commit a6c2c7f

Browse files
neildgopherbot
authored andcommitted
http2, internal/httpcommon: factor out common request header logic for h2/h3
HTTP/2 and HTTP/3 use the same set of pseudo-headers to represent requests and responses. Move the http2 package's logic for validating an http.Request and converting it to a set of pseudo-headers into internal/httpcommon so it can be shared with HTTP/3. For golang/go#70914 Change-Id: I80561752e821ccd0da2a811034c44f3f71064434 Reviewed-on: https://go-review.googlesource.com/c/net/+/643780 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Commit-Queue: Damien Neil <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent c72e89d commit a6c2c7f

File tree

9 files changed

+1184
-407
lines changed

9 files changed

+1184
-407
lines changed

http2/http2.go

-17
Original file line numberDiff line numberDiff line change
@@ -415,23 +415,6 @@ func (s *sorter) SortStrings(ss []string) {
415415
s.v = save
416416
}
417417

418-
// validPseudoPath reports whether v is a valid :path pseudo-header
419-
// value. It must be either:
420-
//
421-
// - a non-empty string starting with '/'
422-
// - the string '*', for OPTIONS requests.
423-
//
424-
// For now this is only used a quick check for deciding when to clean
425-
// up Opaque URLs before sending requests from the Transport.
426-
// See golang.org/issue/16847
427-
//
428-
// We used to enforce that the path also didn't start with "//", but
429-
// Google's GFE accepts such paths and Chrome sends them, so ignore
430-
// that part of the spec. See golang.org/issue/19103.
431-
func validPseudoPath(v string) bool {
432-
return (len(v) > 0 && v[0] == '/') || v == "*"
433-
}
434-
435418
// incomparable is a zero-width, non-comparable type. Adding it to a struct
436419
// makes that struct also non-comparable, and generally doesn't add
437420
// any size (as long as it's first).

http2/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050

5151
"golang.org/x/net/http/httpguts"
5252
"golang.org/x/net/http2/hpack"
53+
"golang.org/x/net/internal/httpcommon"
5354
)
5455

5556
const (
@@ -812,8 +813,7 @@ const maxCachedCanonicalHeadersKeysSize = 2048
812813

813814
func (sc *serverConn) canonicalHeader(v string) string {
814815
sc.serveG.check()
815-
buildCommonHeaderMapsOnce()
816-
cv, ok := commonCanonHeader[v]
816+
cv, ok := httpcommon.CachedCanonicalHeader(v)
817817
if ok {
818818
return cv
819819
}

0 commit comments

Comments
 (0)