From 080aa8e9647e5211650f34f3a93fb493afbe396d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 3 Mar 2026 08:12:25 -0800 Subject: net/http: use net/http/internal/http2 rather than h2_bundle.go Rework net/http/internal/http2 to use internally-defined types rather than net/http types (to avoid an import cycle). Remove h2_bundle.go, and replace it with calls into net/http/internal/http2 instead. For #67810 Change-Id: I56a1b28dbd0e302ab15a30f819dd46256a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/751304 Reviewed-by: Nicholas Husin LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil Reviewed-by: Nicholas Husin --- src/net/http/internal/http2/errors.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/net/http/internal/http2/errors.go') diff --git a/src/net/http/internal/http2/errors.go b/src/net/http/internal/http2/errors.go index f2067dabc5..35c34b7ba5 100644 --- a/src/net/http/internal/http2/errors.go +++ b/src/net/http/internal/http2/errors.go @@ -7,6 +7,7 @@ package http2 import ( "errors" "fmt" + "reflect" ) // An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec. @@ -90,6 +91,33 @@ func (e StreamError) Error() string { return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code) } +// This As function permits converting a StreamError into a x/net/http2.StreamError. +func (e StreamError) As(target any) bool { + dst := reflect.ValueOf(target).Elem() + dstType := dst.Type() + if dstType.Kind() != reflect.Struct { + return false + } + src := reflect.ValueOf(e) + srcType := src.Type() + numField := srcType.NumField() + if dstType.NumField() != numField { + return false + } + for i := 0; i < numField; i++ { + sf := srcType.Field(i) + df := dstType.Field(i) + if sf.Name != df.Name || !sf.Type.ConvertibleTo(df.Type) { + return false + } + } + for i := 0; i < numField; i++ { + df := dst.Field(i) + df.Set(src.Field(i).Convert(df.Type())) + } + return true +} + // 6.9.1 The Flow Control Window // "If a sender receives a WINDOW_UPDATE that causes a flow control // window to exceed this maximum it MUST terminate either the stream -- cgit v1.3-6-g1900