Skip to content

Commit

Permalink
Add more info to router
Browse files Browse the repository at this point in the history
  • Loading branch information
xetorthio committed Sep 19, 2017
1 parent a268ad6 commit 495219c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,15 @@ func (r *proxyRouter) ListenSshAddress() string {
func (r *proxyRouter) handleConnection(c net.Conn) {
defer c.Close()
// first try tls
start := time.Now()
vhostConn, err := vhost.TLS(c)
discoverElapsed := time.Since(start)

if err == nil {
// It is a TLS connection
defer vhostConn.Close()
host := vhostConn.ClientHelloMsg.ServerName
log.Printf("Proxying TLS connection to %s. Discover took %s\n", host, discoverElapsed)
dstHost, err := r.director(ProtocolHTTPS, host)
if err != nil {
log.Printf("Error directing request: %v\n", err)
Expand All @@ -351,7 +354,9 @@ func (r *proxyRouter) handleConnection(c net.Conn) {
// it is not TLS
// treat it as an http connection

start := time.Now()
req, err := http.ReadRequest(bufio.NewReader(vhostConn))
httpReadElapsed := time.Since(start)
if err != nil {
// It is not http neither. So just close the connection.
return
Expand All @@ -360,6 +365,7 @@ func (r *proxyRouter) handleConnection(c net.Conn) {
if host == "" {
host = req.Host
}
log.Printf("Proxying http connection to %s. Discover took %s. Http read took %s\n", host, discoverElapsed, httpReadElapsed)
dstHost, err := r.director(ProtocolHTTP, host)
if err != nil {
log.Printf("Error directing request: %v\n", err)
Expand Down

0 comments on commit 495219c

Please sign in to comment.