Skip to content

Commit 136aec7

Browse files
committed
respect proxy - bitly/oauth2_proxy#556
1 parent 6c6d610 commit 136aec7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

oauthproxy.go

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type UpstreamProxy struct {
8181
}
8282

8383
func (u *UpstreamProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
84+
p.respectForwardedProto(rw, req)
8485
w.Header().Set("GAP-Upstream-Address", u.upstream)
8586
if u.auth != nil {
8687
r.Header.Set("GAP-Auth", w.Header().Get("GAP-Auth"))
@@ -607,6 +608,12 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
607608
}
608609
}
609610

611+
func (p *OAuthProxy) respectForwardedProto(rw http.ResponseWriter, req *http.Request) {
612+
if req.Header.Get("X-Forwarded-Proto") == "http" {
613+
http.Redirect(rw, req, fmt.Sprintf("https://%v%v", req.Host, req.URL), http.StatusMovedPermanently)
614+
}
615+
}
616+
610617
func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) int {
611618
var saveSession, clearSession, revalidated bool
612619
remoteAddr := getRemoteAddr(req)

0 commit comments

Comments
 (0)