func prepareResponseHeaders(res *http.Response) { // remove global hop-by-hop headers. for _, h := range hopHeaders { res.Header.Del(h) } // remove the Upgrade header and headers referenced in the Connection // header if HTTP < 1.1 or if Connection header didn't contain "upgrade": // https://tools.ietf.org/html/rfc7230#section-6.7 if !res.ProtoAtLeast(1, 1) || !isConnectionUpgrade(res.Header) { res.Header.Del("Upgrade") // A proxy or gateway MUST parse a received Connection header field before a // message is forwarded and, for each connection-option in this field, remove // any header field(s) from the message with the same name as the // connection-option, and then remove the Connection header field itself (or // replace it with the intermediary's own connection options for the // forwarded message): https://tools.ietf.org/html/rfc7230#section-6.1 tokens := strings.Split(res.Header.Get("Connection"), ",") for _, hdr := range tokens { res.Header.Del(hdr) } res.Header.Del("Connection") } }