Skip to content

Commit

Permalink
test: false for isHTTPSRequest
Browse files Browse the repository at this point in the history
As suggested in
ipfs/kubo#7847 (comment)


This commit was moved from ipfs/kubo@88dd257
  • Loading branch information
lidel committed Jan 7, 2021
1 parent 9da8851 commit f554a8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gateway/core/corehttp/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func toDNSLabel(rootID string, rootCID cid.Cid) (dnsCID string, err error) {
}

// Returns true if HTTP request involves TLS certificate.
// See https://github.com/ipfs/in-web-browsers/issues/169 to uderstand how it
// See https://github.com/ipfs/in-web-browsers/issues/169 to understand how it
// impacts DNSLink websites on public gateways.
func isHTTPSRequest(r *http.Request) bool {
// X-Forwarded-Proto if added by a reverse proxy
Expand Down
5 changes: 5 additions & 0 deletions gateway/core/corehttp/hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,18 @@ func TestIsHTTPSRequest(t *testing.T) {
httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil)
httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil)
httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https")
httpProxiedRequest := httptest.NewRequest("GET", "http://proxied-http-request-stub.example.com", nil)
httpProxiedRequest.Header.Set("X-Forwarded-Proto", "http")
oddballRequest := httptest.NewRequest("GET", "foo://127.0.0.1:8080", nil)
for _, test := range []struct {
in *http.Request
out bool
}{
{httpRequest, false},
{httpsRequest, true},
{httpsProxiedRequest, true},
{httpProxiedRequest, false},
{oddballRequest, false},
} {
out := isHTTPSRequest(test.in)
if out != test.out {
Expand Down

0 comments on commit f554a8b

Please sign in to comment.