server: properly do X-Forwarded-For
This commit is contained in:
parent
69830acffb
commit
3c16032955
|
@ -127,10 +127,23 @@ func (s *Server) onionPath(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
|
r.Header.Del("X-Forwarded-For")
|
||||||
|
|
||||||
|
if r.Header.Get("X-Tor2web") != "" {
|
||||||
|
http.Error(w, "tor2web proxy use is not allowed", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.Header.Set("X-Forwarded-For", host)
|
||||||
|
r.Header.Set("X-Remote-IP", host)
|
||||||
r.Header.Set("X-Request-Ingress", time.Now().String())
|
r.Header.Set("X-Request-Ingress", time.Now().String())
|
||||||
|
|
||||||
if r.RequestURI == rpc.DefaultRPCPath {
|
if r.RequestURI == rpc.DefaultRPCPath && r.Host == "127.0.0.1:"+s.cfg.WebPort {
|
||||||
s.rpcS.ServeHTTP(w, r)
|
s.rpcS.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue