From f74c508212d931e711aebd13a51f04748bbe7e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Ch=C3=A1vez?= Date: Mon, 19 Jun 2023 22:44:04 +0200 Subject: [PATCH] feat: readds transfer encoding to the header list. Transfer-Encoding property turns into a request field by the http handler, this commit adds it back for the sake of correctness. --- handler/nethttp/host.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/handler/nethttp/host.go b/handler/nethttp/host.go index a73e3f5..b40ceef 100644 --- a/handler/nethttp/host.go +++ b/handler/nethttp/host.go @@ -88,14 +88,25 @@ func (host) GetRequestHeaderNames(ctx context.Context) (names []string) { count := len(r.Header) i := 0 if r.Host != "" { // special-case the host header. - count++ - names = make([]string, count) + names = make([]string, count+2) names[i] = "Host" i++ - } else if count == 0 { - return nil - } else { - names = make([]string, count) + } + + if len(r.TransferEncoding) > 0 { + if i == 0 { + names = make([]string, count+1) + } + names[i] = "Transfer-Encoding" + i++ + } + + if i == 0 { + if count == 0 { + return nil + } else { + names = make([]string, count) + } } for n := range r.Header { @@ -118,8 +129,11 @@ func (host) GetRequestHeaderNames(ctx context.Context) (names []string) { // GetRequestHeaderValues implements the same method as documented on handler.Host. func (host) GetRequestHeaderValues(ctx context.Context, name string) []string { r := requestStateFromContext(ctx).r - if textproto.CanonicalMIMEHeaderKey(name) == "Host" { // special-case the host header. + switch textproto.CanonicalMIMEHeaderKey(name) { + case "Host": // special-case the host header. return []string{r.Host} + case "Transfer-Encoding": + return r.TransferEncoding } return r.Header.Values(name) }