Skip to content

Commit 922a636

Browse files
committed
Merge pull request #1 from yp-engineering/request_url
Add support for X-Forwarded-Proto header when building service URL.
2 parents 985937a + a21dd1f commit 922a636

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

client.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func requestURL(r *http.Request) (*url.URL, error) {
7171
u.Host = r.Host
7272
u.Scheme = "http"
7373

74-
if r.TLS != nil {
74+
if scheme := r.Header.Get("X-Forwarded-Proto"); scheme != "" {
75+
u.Scheme = scheme
76+
} else if r.TLS != nil {
7577
u.Scheme = "https"
7678
}
7779

client_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ func TestUnauthenticatedRequestShouldRedirectToCasURL(t *testing.T) {
4747
t.Errorf("Expected response to have Set-Cookie header with <%v>, got <%v>",
4848
sessionCookieName, setCookie)
4949
}
50+
51+
req.Header.Set("X-Forwarded-Proto", "https")
52+
handler.ServeHTTP(w, req)
53+
if w.Code != http.StatusFound {
54+
t.Errorf("Expected HTTP response code to be <%v>, got <%v>", http.StatusFound, w.Code)
55+
}
56+
57+
loc = w.Header().Get("Location")
58+
exp = "https://cas.example.com/login?service=https%3A%2F%2Fexample.com%2F"
59+
if loc != exp {
60+
t.Errorf("Expected HTTP redirect to <%s>, got <%s>", exp, loc)
61+
}
5062
}
5163

5264
func TestInvalidServiceTicket(t *testing.T) {

doc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"net/url"
88

9-
"gopkg.in/cas.v0"
9+
"gopkg.in/cas.v1"
1010
)
1111

1212
func ExampleRedirectToLogin() {

0 commit comments

Comments
 (0)