Skip to content

Commit

Permalink
http2, internal/httpcommon: factor out common request header logic fo…
Browse files Browse the repository at this point in the history
…r 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]>
  • Loading branch information
neild authored and gopherbot committed Jan 24, 2025
1 parent c72e89d commit a6c2c7f
Show file tree
Hide file tree
Showing 9 changed files with 1,184 additions and 407 deletions.
17 changes: 0 additions & 17 deletions http2/http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +415,6 @@ func (s *sorter) SortStrings(ss []string) {
s.v = save
}

// validPseudoPath reports whether v is a valid :path pseudo-header
// value. It must be either:
//
// - a non-empty string starting with '/'
// - the string '*', for OPTIONS requests.
//
// For now this is only used a quick check for deciding when to clean
// up Opaque URLs before sending requests from the Transport.
// See golang.org/issue/16847
//
// We used to enforce that the path also didn't start with "//", but
// Google's GFE accepts such paths and Chrome sends them, so ignore
// that part of the spec. See golang.org/issue/19103.
func validPseudoPath(v string) bool {
return (len(v) > 0 && v[0] == '/') || v == "*"
}

// incomparable is a zero-width, non-comparable type. Adding it to a struct
// makes that struct also non-comparable, and generally doesn't add
// any size (as long as it's first).
Expand Down
4 changes: 2 additions & 2 deletions http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (

"golang.org/x/net/http/httpguts"
"golang.org/x/net/http2/hpack"
"golang.org/x/net/internal/httpcommon"
)

const (
Expand Down Expand Up @@ -812,8 +813,7 @@ const maxCachedCanonicalHeadersKeysSize = 2048

func (sc *serverConn) canonicalHeader(v string) string {
sc.serveG.check()
buildCommonHeaderMapsOnce()
cv, ok := commonCanonHeader[v]
cv, ok := httpcommon.CachedCanonicalHeader(v)
if ok {
return cv
}
Expand Down
Loading

0 comments on commit a6c2c7f

Please sign in to comment.