Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter scheme header #634

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/context/httprequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package context
import (
"io"
"net/http"
"strings"

"github.com/tomasen/realip"

Expand All @@ -38,6 +39,10 @@ type (
}
)

const (
xForwardedProto = "X-Forwarded-Proto"
)

func newHTTPRequest(stdr *http.Request) *httpRequest {
// Reference: https://golang.org/pkg/net/http/#Request
//
Expand Down Expand Up @@ -96,8 +101,15 @@ func (r *httpRequest) Scheme() string {
return scheme
}

if scheme := r.std.Header.Get("X-Forwarded-Proto"); scheme != "" {
return scheme
if scheme := r.std.Header.Get(xForwardedProto); scheme != "" {
// note some proxy servers will append data in this format,
// and the last one is sent by the last proxy-server and should use for easegress's proxy
// header : {
// some-key: "ele1, ele2, ele3"
// }
// https://github.com/spring-cloud/spring-cloud-gateway/ ProxyExchange.java#appendXForwarded()
schemes := strings.Split(scheme, ",")
return schemes[len(schemes)-1]
}

if r.std.TLS != nil {
Expand Down