Skip to content

Commit

Permalink
refactor: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens committed Nov 23, 2017
1 parent c7f6852 commit 46f31cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions forward/fwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ type httpForwarder struct {
}

const (
StateConnected = iota
defaultFlushInterval = time.Duration(100) * time.Millisecond
StateConnected = iota
StateDisconnected
)

Expand All @@ -177,7 +178,7 @@ func New(setters ...optSetter) (*Forwarder, error) {
if !f.stream {
f.flushInterval = 0
} else if f.flushInterval == 0 {
f.flushInterval = time.Duration(100) * time.Millisecond
f.flushInterval = defaultFlushInterval
}

if f.httpForwarder.rewriter == nil {
Expand Down Expand Up @@ -224,16 +225,17 @@ func (f *Forwarder) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
}

func (f *httpForwarder) modifyRequest(outReq *http.Request, u *url.URL) {
// Modify the request to handle the target URL
func (f *httpForwarder) modifyRequest(outReq *http.Request, target *url.URL) {
outReq.URL = utils.CopyURL(outReq.URL)
outReq.URL.Scheme = u.Scheme
outReq.URL.Host = u.Host
outReq.URL.Scheme = target.Scheme
outReq.URL.Host = target.Host
outReq.URL.Opaque = outReq.RequestURI
// raw query is already included in RequestURI, so ignore it to avoid dupes
outReq.URL.RawQuery = ""
// Do not pass client Host header unless optsetter PassHostHeader is set.
if !f.passHost {
outReq.Host = u.Host
outReq.Host = target.Host
}

outReq.Proto = "HTTP/1.1"
Expand Down
2 changes: 1 addition & 1 deletion forward/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (rw *HeaderRewriter) Rewrite(req *http.Request) {
}
}

if xfp := req.Header.Get(XForwardedPort); xfp == "" {
if xfPort := req.Header.Get(XForwardedPort); xfPort == "" {
req.Header.Set(XForwardedPort, forwardedPort(req))
}

Expand Down

0 comments on commit 46f31cf

Please sign in to comment.