TUN-2745: Rename existing header management functions
This commit is contained in:
parent
269351bbea
commit
52ab2c8227
|
@ -17,10 +17,10 @@ type Header struct {
|
||||||
|
|
||||||
var headerEncoding = base64.RawStdEncoding
|
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
|
// 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
|
// 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 {
|
for _, header := range h2 {
|
||||||
switch header.Name {
|
switch header.Name {
|
||||||
case ":method":
|
case ":method":
|
||||||
|
@ -73,7 +73,7 @@ func H2RequestHeadersToH1Request(h2 []Header, h1 *http.Request) error {
|
||||||
return nil
|
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)}}
|
h2 = []Header{{Name: ":status", Value: fmt.Sprintf("%d", h1.StatusCode)}}
|
||||||
for headerName, headerValues := range h1.Header {
|
for headerName, headerValues := range h1.Header {
|
||||||
for _, headerValue := range headerValues {
|
for _, headerValue := range headerValues {
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestH2RequestHeadersToH1Request_RegularHeaders(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{
|
[]Header{
|
||||||
{
|
{
|
||||||
Name: "Mock header 1",
|
Name: "Mock header 1",
|
||||||
|
@ -45,7 +45,7 @@ func TestH2RequestHeadersToH1Request_NoHeaders(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{},
|
[]Header{},
|
||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
|
@ -59,7 +59,7 @@ func TestH2RequestHeadersToH1Request_InvalidHostPath(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
request, err := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{
|
[]Header{
|
||||||
{
|
{
|
||||||
Name: ":path",
|
Name: ":path",
|
||||||
|
@ -86,7 +86,7 @@ func TestH2RequestHeadersToH1Request_HostPathWithQuery(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil)
|
request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{
|
[]Header{
|
||||||
{
|
{
|
||||||
Name: ":path",
|
Name: ":path",
|
||||||
|
@ -113,7 +113,7 @@ func TestH2RequestHeadersToH1Request_HostPathWithURLEncoding(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil)
|
request, err := http.NewRequest(http.MethodGet, "http://example.com/", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{
|
[]Header{
|
||||||
{
|
{
|
||||||
Name: ":path",
|
Name: ":path",
|
||||||
|
@ -276,7 +276,7 @@ func TestH2RequestHeadersToH1Request_WeirdURLs(t *testing.T) {
|
||||||
|
|
||||||
request, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
request, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
headersConversionErr := H2RequestHeadersToH1Request(
|
headersConversionErr := OldH2RequestHeadersToH1Request(
|
||||||
[]Header{
|
[]Header{
|
||||||
{
|
{
|
||||||
Name: ":path",
|
Name: ":path",
|
||||||
|
@ -362,7 +362,7 @@ func TestH2RequestHeadersToH1Request_QuickCheck(t *testing.T) {
|
||||||
h1, err := http.NewRequest("GET", testOrigin.url, nil)
|
h1, err := http.NewRequest("GET", testOrigin.url, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = H2RequestHeadersToH1Request(h2, h1)
|
err = OldH2RequestHeadersToH1Request(h2, h1)
|
||||||
return assert.NoError(t, err) &&
|
return assert.NoError(t, err) &&
|
||||||
assert.Equal(t, expectedMethod, h1.Method) &&
|
assert.Equal(t, expectedMethod, h1.Method) &&
|
||||||
assert.Equal(t, expectedHostname, h1.Host) &&
|
assert.Equal(t, expectedHostname, h1.Host) &&
|
||||||
|
|
|
@ -580,7 +580,7 @@ func (h *TunnelHandler) createRequest(stream *h2mux.MuxedStream) (*http.Request,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Unexpected error from http.NewRequest")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "invalid request received")
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
err = stream.WriteHeaders(h2mux.H1ResponseToH2ResponseHeaders(response))
|
err = stream.WriteHeaders(h2mux.OldH1ResponseToH2ResponseHeaders(response))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Error writing response header")
|
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()
|
defer response.Body.Close()
|
||||||
|
|
||||||
err = stream.WriteHeaders(h2mux.H1ResponseToH2ResponseHeaders(response))
|
err = stream.WriteHeaders(h2mux.OldH1ResponseToH2ResponseHeaders(response))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Error writing response header")
|
return nil, errors.Wrap(err, "Error writing response header")
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func createRequest(stream *h2mux.MuxedStream, url *url.URL) (*http.Request, erro
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "unexpected error from http.NewRequest")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "invalid request received")
|
return nil, errors.Wrap(err, "invalid request received")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue