Browse Source

Fixing over-rides of public port so that they don't result in mis-matched host names due to Request.Host including the port in the returned hostname.

Stephen Huenneke 12 years ago
parent
commit
aea0524bb5
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/ngrok/server/http.go

+ 6 - 4
src/ngrok/server/http.go

@@ -3,6 +3,7 @@ package server
 import (
 	"fmt"
 	"net"
+	"strings"
 	"ngrok/conn"
 	"ngrok/log"
 )
@@ -68,11 +69,12 @@ func httpHandler(tcpConn net.Conn) {
 	}
 
 	// multiplex to find the right backend host
-	conn.Debug("Found hostname %s in request", req.Host)
-	tunnel := tunnels.Get("http://" + req.Host)
+	host := strings.Split(req.Host, ":")[0]
+	conn.Debug("Found hostname %s in request", host)
+	tunnel := tunnels.Get("http://" + host)
 	if tunnel == nil {
-		conn.Info("No tunnel found for hostname %s", req.Host)
-		conn.Write([]byte(fmt.Sprintf(NotFound, len(req.Host)+18, req.Host)))
+		conn.Info("No tunnel found for hostname %s", host)
+		conn.Write([]byte(fmt.Sprintf(NotFound, len(host)+18, host)))
 		return
 	}