Skip to content

Commit

Permalink
fix bug in relay which couldn't handle regular http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Jul 5, 2018
1 parent 1e9ec94 commit e01deec
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ func (c *Croc) startServer() (err error) {
// incoming websocket request
log.Debugf("connecting remote addr: %+v", r.RemoteAddr)
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
if _, ok := r.Header["X-Forwarded-For"]; ok {
address = r.Header["X-Forwarded-For"][0]
}
if _, ok := r.Header["X-Real-Ip"]; ok {
address = r.Header["X-Real-Ip"][0]
}
log.Debugf("ws address: %s", ws.RemoteAddr().String())
log.Debug("getting lock")
c.rs.Lock()
c.rs.ips[ws.RemoteAddr().String()] = address
c.rs.Unlock()
Expand Down

0 comments on commit e01deec

Please sign in to comment.