mirror of
https://github.com/nadoo/glider.git
synced 2025-02-24 01:45:39 +08:00
http: add param xsi for "X-Server-IP" header
This commit is contained in:
parent
7e9e737922
commit
12f15be1dc
18
http.go
18
http.go
@ -24,7 +24,8 @@ type HTTP struct {
|
|||||||
|
|
||||||
user string
|
user string
|
||||||
password string
|
password string
|
||||||
xff bool
|
xff bool // X-Forwarded-For
|
||||||
|
xsi bool // X-Server-IP
|
||||||
|
|
||||||
selfip string
|
selfip string
|
||||||
}
|
}
|
||||||
@ -47,6 +48,12 @@ func NewHTTP(addr, user, pass, rawQuery string, cDialer Dialer, sDialer Dialer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := p["xsi"]; ok {
|
||||||
|
if v[0] == "true" {
|
||||||
|
s.xsi = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,13 +173,8 @@ func (s *HTTP) Serve(c net.Conn) {
|
|||||||
respHeader.Set("Proxy-Connection", "close")
|
respHeader.Set("Proxy-Connection", "close")
|
||||||
respHeader.Set("Connection", "close")
|
respHeader.Set("Connection", "close")
|
||||||
|
|
||||||
if s.xff {
|
if s.xsi {
|
||||||
if respHeader.Get("X-Forwarded-For") != "" {
|
respHeader.Set("X-Server-IP", rc.RemoteAddr().(*net.TCPAddr).IP.String())
|
||||||
respHeader.Add("X-Forwarded-For", ",")
|
|
||||||
}
|
|
||||||
respHeader.Add("X-Forwarded-For", rc.RemoteAddr().(*net.TCPAddr).IP.String())
|
|
||||||
respHeader.Add("X-Forwarded-For", ",")
|
|
||||||
respHeader.Add("X-Forwarded-For", s.selfip)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var respBuf bytes.Buffer
|
var respBuf bytes.Buffer
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Glider Service (%i)
|
Description=Glider Service (%i)
|
||||||
After=network.target
|
After=network.target
|
||||||
|
Before=iptables.service ip6tables.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
@ -48,24 +48,22 @@ func (s *UoTTun) ListenAndServe() {
|
|||||||
rc, err := s.sDialer.Dial("uot", s.raddr)
|
rc, err := s.sDialer.Dial("uot", s.raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf("proxy-uottun failed to connect to server %v: %v", s.raddr, err)
|
logf("proxy-uottun failed to connect to server %v: %v", s.raddr, err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.Write(buf[:n])
|
rc.Write(buf[:n])
|
||||||
|
|
||||||
// no remote forwarder, just a local udp forwarder
|
// no remote forwarder, just a local udp forwarder
|
||||||
if urc, ok := rc.(*net.UDPConn); ok {
|
if urc, ok := rc.(*net.UDPConn); ok {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
timedCopy(c, clientAddr, urc, 5*time.Minute, false)
|
timedCopy(c, clientAddr, urc, 5*time.Minute, false)
|
||||||
urc.Close()
|
urc.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
} else { // remote forwarder, udp over tcp
|
} else { // remote forwarder, udp over tcp
|
||||||
resp, err := ioutil.ReadAll(rc)
|
resp, err := ioutil.ReadAll(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf("error in ioutil.ReadAll: %s\n", err)
|
logf("error in ioutil.ReadAll: %s\n", err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
rc.Close()
|
rc.Close()
|
||||||
c.WriteTo(resp, clientAddr)
|
c.WriteTo(resp, clientAddr)
|
||||||
|
Loading…
Reference in New Issue
Block a user