1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 08:02:33 +03:00

fix bug in relay which couldn't handle regular http requests

This commit is contained in:
Zack Scholl 2018-07-05 14:31:47 -07:00
parent 4e88975ed4
commit 11566c710d

View File

@ -28,6 +28,11 @@ func (c *Croc) startServer() (err error) {
// incoming websocket request // incoming websocket request
log.Debugf("connecting remote addr: %+v", r.RemoteAddr) log.Debugf("connecting remote addr: %+v", r.RemoteAddr)
ws, err := upgrader.Upgrade(w, r, nil) ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Debugf("err in websocket: %s", err.Error())
fmt.Fprintf(w, "?")
return
}
address := r.RemoteAddr address := r.RemoteAddr
if _, ok := r.Header["X-Forwarded-For"]; ok { if _, ok := r.Header["X-Forwarded-For"]; ok {
address = r.Header["X-Forwarded-For"][0] address = r.Header["X-Forwarded-For"][0]
@ -35,6 +40,8 @@ func (c *Croc) startServer() (err error) {
if _, ok := r.Header["X-Real-Ip"]; ok { if _, ok := r.Header["X-Real-Ip"]; ok {
address = r.Header["X-Real-Ip"][0] address = r.Header["X-Real-Ip"][0]
} }
log.Debugf("ws address: %s", ws.RemoteAddr().String())
log.Debug("getting lock")
c.rs.Lock() c.rs.Lock()
c.rs.ips[ws.RemoteAddr().String()] = address c.rs.ips[ws.RemoteAddr().String()] = address
c.rs.Unlock() c.rs.Unlock()