mirror of
https://github.com/golang/go
synced 2024-11-18 13:14:47 -07:00
37a1062ad0
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>
26 lines
720 B
Go
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)
|
|
}
|
|
}
|