Skip to content

Commit

Permalink
Merge pull request #1 from yp-engineering/request_url
Browse files Browse the repository at this point in the history
Add support for X-Forwarded-Proto header when building service URL.
  • Loading branch information
geoffgarside committed Sep 17, 2015
2 parents 985937a + a21dd1f commit 922a636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func requestURL(r *http.Request) (*url.URL, error) {
u.Host = r.Host
u.Scheme = "http"

if r.TLS != nil {
if scheme := r.Header.Get("X-Forwarded-Proto"); scheme != "" {
u.Scheme = scheme
} else if r.TLS != nil {
u.Scheme = "https"
}

Expand Down
12 changes: 12 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ func TestUnauthenticatedRequestShouldRedirectToCasURL(t *testing.T) {
t.Errorf("Expected response to have Set-Cookie header with <%v>, got <%v>",
sessionCookieName, setCookie)
}

req.Header.Set("X-Forwarded-Proto", "https")
handler.ServeHTTP(w, req)
if w.Code != http.StatusFound {
t.Errorf("Expected HTTP response code to be <%v>, got <%v>", http.StatusFound, w.Code)
}

loc = w.Header().Get("Location")
exp = "https://cas.example.com/login?service=https%3A%2F%2Fexample.com%2F"
if loc != exp {
t.Errorf("Expected HTTP redirect to <%s>, got <%s>", exp, loc)
}
}

func TestInvalidServiceTicket(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"net/url"

"gopkg.in/cas.v0"
"gopkg.in/cas.v1"
)

func ExampleRedirectToLogin() {
Expand Down

0 comments on commit 922a636

Please sign in to comment.