Skip to content

Commit 33ab965

Browse files
committed
log X-Forwarded-For if present.
1 parent 59454e8 commit 33ab965

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ func redirect(w http.ResponseWriter, req *http.Request) {
3838
if len(req.URL.RawQuery) > 0 {
3939
target += "?" + req.URL.RawQuery
4040
}
41-
log.Printf("redirect to: %s from: %s", target, req.RemoteAddr)
42-
http.Redirect(w, req, target,
43-
http.StatusTemporaryRedirect)
41+
if xff := req.Header.Get("X-Forwarded-For"); xff != "" {
42+
log.Printf("redirect to: %s from: %s xff %s", target, req.RemoteAddr, xff)
43+
} else {
44+
log.Printf("redirect to: %s from: %s", target, req.RemoteAddr)
45+
}
46+
http.Redirect(w, req, target, http.StatusTemporaryRedirect)
4447
}
4548

4649
func main() {

0 commit comments

Comments
 (0)