Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for HTTP/2 #101

Merged
merged 4 commits into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ func TestProxy(t *testing.T) {
}
}

func TestProxyHTTP2(t *testing.T) {
var r requestLogger
server := httptest.NewUnstartedServer(r.log("server", http.NewServeMux()))
server.EnableHTTP2 = true
server.StartTLS()
defer server.Close()
proxy := httptest.NewServer(r.log("proxy", newDirectProxy()))
defer proxy.Close()
client := &http.Client{
Transport: &http.Transport{
Proxy: proxyServer(t, proxy),
TLSClientConfig: tlsConfig(server),
ForceAttemptHTTP2: true,
},
}
resp, err := client.Get(server.URL)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, 2, resp.ProtoMajor)
assert.Equal(t, []string{"CONNECT to proxy", "GET to server"}, r.requests)
}

func newDirectProxy() ProxyHandler {
return NewProxyHandler(nil, http.ProxyURL(nil), func(string) {})
}
Expand Down