1
0
mirror of https://github.com/golang/go synced 2024-10-01 16:18:32 -06:00
go/cmd/tip/tip_test.go
Kevin Burke 37a1062ad0 cmd/tip: redirect http://tip.golang.org to https
At some point we switched tip.golang.org to run in GKE, which
terminates TLS directly on port 443. This requires a new technique
for detecting a plain HTTP connection. In addition we may want to run
talks.golang.org on App Engine Flex, which uses an X-Forwarded-Proto
header to indicate HTTP, so let's prepare for that possibility.

Fixes golang/go#19759.

Change-Id: Iddc567214c5d28f61c405db065aa1b3f2c92fd85
Reviewed-on: https://go-review.googlesource.com/38800
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-03 05:32:14 +00:00

26 lines
720 B
Go

// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"net/http/httptest"
"testing"
)
func TestTipRedirects(t *testing.T) {
mux := newServeMux(&Proxy{builder: &godocBuilder{}})
req := httptest.NewRequest("GET", "http://example.com/foo?bar=baz", nil)
req.Header.Set("X-Forwarded-Proto", "http")
w := httptest.NewRecorder()
mux.ServeHTTP(w, req)
if w.Code != 302 {
t.Errorf("expected Code to be 302, got %d", w.Code)
}
want := "https://example.com/foo?bar=baz"
if loc := w.Header().Get("Location"); loc != want {
t.Errorf("Location header: got %s, want %s", loc, want)
}
}