Skip to content

Commit 93164c9

Browse files
authored
Merge pull request #83 from MrMarvin/x_forwarded_proto_from_serving
Fixes setting of X-Forwarded-For-Proto
2 parents 53bd117 + 3e85d01 commit 93164c9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cmd/devd/devd.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,19 @@ func main() {
187187
hdrs.Set("Access-Control-Allow-Origin", "*")
188188
}
189189

190+
var servingScheme string
191+
if *tls {
192+
servingScheme = "https"
193+
} else {
194+
servingScheme = "http"
195+
}
196+
190197
dd := devd.Devd{
191198
// Shaping
192199
Latency: *latency,
193200
DownKbps: *downKbps,
194201
UpKbps: *upKbps,
202+
ServingScheme: servingScheme,
195203

196204
AddHeaders: &hdrs,
197205

reverseproxy/reverseproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func singleJoiningSlash(a, b string) string {
7171
func NewSingleHostReverseProxy(target *url.URL, ci inject.CopyInject) *ReverseProxy {
7272
targetQuery := target.RawQuery
7373
director := func(req *http.Request) {
74-
req.URL.Scheme = target.Scheme
7574
req.URL.Host = target.Host
7675
req.URL.Path = singleJoiningSlash(target.Path, req.URL.Path)
7776
if req.Header.Get("X-Forwarded-Host") == "" {
@@ -80,6 +79,7 @@ func NewSingleHostReverseProxy(target *url.URL, ci inject.CopyInject) *ReversePr
8079
if req.Header.Get("X-Forwarded-Proto") == "" {
8180
req.Header.Set("X-Forwarded-Proto", req.URL.Scheme)
8281
}
82+
req.URL.Scheme = target.Scheme
8383

8484
// Set "identity"-only content encoding, in order for injector to
8585
// work on text response

server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type Devd struct {
139139
Latency int
140140
DownKbps uint
141141
UpKbps uint
142+
ServingScheme string
142143

143144
// Add headers
144145
AddHeaders *http.Header
@@ -163,6 +164,7 @@ type Devd struct {
163164
// logging, latency, and so forth.
164165
func (dd *Devd) WrapHandler(log termlog.TermLog, next httpctx.Handler) http.Handler {
165166
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
167+
r.URL.Scheme = dd.ServingScheme
166168
revertOriginalHost(r)
167169
timr := timer.Timer{}
168170
sublog := log.Group()
@@ -177,7 +179,7 @@ func (dd *Devd) WrapHandler(log termlog.TermLog, next httpctx.Handler) http.Hand
177179
timr.RequestHeaders()
178180
time.Sleep(time.Millisecond * time.Duration(dd.Latency))
179181

180-
dpath := r.URL.String()
182+
dpath := r.RequestURI
181183
if !strings.HasPrefix(dpath, "/") {
182184
dpath = "/" + dpath
183185
}

0 commit comments

Comments
 (0)