test: false for isHTTPSRequest
As suggested in https://github.com/ipfs/go-ipfs/pull/7847#discussion_r551933162
Marcin Rataj committed
Jan 8, 2021 at 00:31 UTC
88dd257ace53b56759a760ab9df189e43a7fda17
2 files changed
+6
-1
core/corehttp/hostname.go
+1
-1
@@ -414,7 +414,7 @@ func toDNSLabel(rootID string, rootCID cid.Cid) (dnsCID string, err error) {
414
}
415
416
// Returns true if HTTP request involves TLS certificate.
417
-// See https://github.com/ipfs/in-web-browsers/issues/169 to uderstand how it
417
+// See https://github.com/ipfs/in-web-browsers/issues/169 to understand how it
418
// impacts DNSLink websites on public gateways.
419
func isHTTPSRequest(r *http.Request) bool {
420
// X-Forwarded-Proto if added by a reverse proxy
core/corehttp/hostname_test.go
+5
@@ -106,6 +106,9 @@ func TestIsHTTPSRequest(t *testing.T) {
106
httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil)
107
httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil)
108
httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https")
109
+ httpProxiedRequest := httptest.NewRequest("GET", "http://proxied-http-request-stub.example.com", nil)
110
+ httpProxiedRequest.Header.Set("X-Forwarded-Proto", "http")
111
+ oddballRequest := httptest.NewRequest("GET", "foo://127.0.0.1:8080", nil)
112
for _, test := range []struct {
113
in *http.Request
114
out bool
@@ -113,6 +116,8 @@ func TestIsHTTPSRequest(t *testing.T) {
116
{httpRequest, false},
117
{httpsRequest, true},
118
{httpsProxiedRequest, true},
119
+ {httpProxiedRequest, false},
120
+ {oddballRequest, false},
121
} {
122
out := isHTTPSRequest(test.in)
123
if out != test.out {