From 52ab2c8227946b17faa17fd72e9a4c4a7ecf9a17 Mon Sep 17 00:00:00 2001 From: Areg Harutyunyan Date: Thu, 20 Feb 2020 19:41:31 +0000 Subject: [PATCH] TUN-2745: Rename existing header management functions --- h2mux/header.go | 6 +++--- h2mux/header_test.go | 14 +++++++------- origin/tunnel.go | 6 +++--- streamhandler/request.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/h2mux/header.go b/h2mux/header.go index 4da9e03c..822f99bb 100644 --- a/h2mux/header.go +++ b/h2mux/header.go @@ -17,10 +17,10 @@ type Header struct { var headerEncoding = base64.RawStdEncoding -// H2RequestHeadersToH1Request converts the HTTP/2 headers to an HTTP/1 Request +// OldH2RequestHeadersToH1Request converts the HTTP/2 headers to an HTTP/1 Request // object. This includes conversion of the pseudo-headers into their closest // HTTP/1 equivalents. See https://tools.ietf.org/html/rfc7540#section-8.1.2.3 -func H2RequestHeadersToH1Request(h2 []Header, h1 *http.Request) error { +func OldH2RequestHeadersToH1Request(h2 []Header, h1 *http.Request) error { for _, header := range h2 { switch header.Name { case ":method": @@ -73,7 +73,7 @@ func H2RequestHeadersToH1Request(h2 []Header, h1 *http.Request) error { return nil } -func H1ResponseToH2ResponseHeaders(h1 *http.Response) (h2 []Header) { +func OldH1ResponseToH2ResponseHeaders(h1 *http.Response) (h2 []Header) { h2 = []Header{{Name: ":status", Value: fmt.Sprintf("%d", h1.StatusCode)}} for headerName, headerValues := range h1.Header { for _, headerValue := range headerValues { diff --git a/h2mux/header_test.go b/h2mux/header_test.go index 83c7ac35..8c5301eb 100644 --- a/h2mux/header_test.go +++ b/h2mux/header_test.go @@ -19,7 +19,7 @@ func TestH2RequestHeadersToH1Request_RegularHeaders(t *testing.T) { request, err := http.NewRequest(http.MethodGet, "http://example.com", nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{ { Name: "Mock header 1", @@ -45,7 +45,7 @@ func TestH2RequestHeadersToH1Request_NoHeaders(t *testing.T) { request, err := http.NewRequest(http.MethodGet, "http://example.com", nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{}, request, ) @@ -59,7 +59,7 @@ func TestH2RequestHeadersToH1Request_InvalidHostPath(t *testing.T) { request, err := http.NewRequest(http.MethodGet, "http://example.com", nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{ { Name: ":path", @@ -86,7 +86,7 @@ func TestH2RequestHeadersToH1Request_HostPathWithQuery(t *testing.T) { request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{ { Name: ":path", @@ -113,7 +113,7 @@ func TestH2RequestHeadersToH1Request_HostPathWithURLEncoding(t *testing.T) { request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{ { Name: ":path", @@ -276,7 +276,7 @@ func TestH2RequestHeadersToH1Request_WeirdURLs(t *testing.T) { request, err := http.NewRequest(http.MethodGet, requestURL, nil) assert.NoError(t, err) - headersConversionErr := H2RequestHeadersToH1Request( + headersConversionErr := OldH2RequestHeadersToH1Request( []Header{ { Name: ":path", @@ -362,7 +362,7 @@ func TestH2RequestHeadersToH1Request_QuickCheck(t *testing.T) { h1, err := http.NewRequest("GET", testOrigin.url, nil) require.NoError(t, err) - err = H2RequestHeadersToH1Request(h2, h1) + err = OldH2RequestHeadersToH1Request(h2, h1) return assert.NoError(t, err) && assert.Equal(t, expectedMethod, h1.Method) && assert.Equal(t, expectedHostname, h1.Host) && diff --git a/origin/tunnel.go b/origin/tunnel.go index 4ee6b55e..d5ba4d71 100644 --- a/origin/tunnel.go +++ b/origin/tunnel.go @@ -580,7 +580,7 @@ func (h *TunnelHandler) createRequest(stream *h2mux.MuxedStream) (*http.Request, if err != nil { return nil, errors.Wrap(err, "Unexpected error from http.NewRequest") } - err = h2mux.H2RequestHeadersToH1Request(stream.Headers, req) + err = h2mux.OldH2RequestHeadersToH1Request(stream.Headers, req) if err != nil { return nil, errors.Wrap(err, "invalid request received") } @@ -599,7 +599,7 @@ func (h *TunnelHandler) serveWebsocket(stream *h2mux.MuxedStream, req *http.Requ return nil, err } defer conn.Close() - err = stream.WriteHeaders(h2mux.H1ResponseToH2ResponseHeaders(response)) + err = stream.WriteHeaders(h2mux.OldH1ResponseToH2ResponseHeaders(response)) if err != nil { return nil, errors.Wrap(err, "Error writing response header") } @@ -633,7 +633,7 @@ func (h *TunnelHandler) serveHTTP(stream *h2mux.MuxedStream, req *http.Request) } defer response.Body.Close() - err = stream.WriteHeaders(h2mux.H1ResponseToH2ResponseHeaders(response)) + err = stream.WriteHeaders(h2mux.OldH1ResponseToH2ResponseHeaders(response)) if err != nil { return nil, errors.Wrap(err, "Error writing response header") } diff --git a/streamhandler/request.go b/streamhandler/request.go index b6bb55d3..52d69bc2 100644 --- a/streamhandler/request.go +++ b/streamhandler/request.go @@ -26,7 +26,7 @@ func createRequest(stream *h2mux.MuxedStream, url *url.URL) (*http.Request, erro if err != nil { return nil, errors.Wrap(err, "unexpected error from http.NewRequest") } - err = h2mux.H2RequestHeadersToH1Request(stream.Headers, req) + err = h2mux.OldH2RequestHeadersToH1Request(stream.Headers, req) if err != nil { return nil, errors.Wrap(err, "invalid request received") }