Skip to content

Commit

Permalink
adapter scheme header (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
sodaRyCN committed Jun 28, 2022
1 parent de365ae commit 4cc51ac
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit 4cc51ac

Please sign in to comment.