utils/vhost: update for vhost_https

This commit is contained in:
fatedier
2016-06-24 15:43:58 +08:00
parent 0a50c3bd82
commit b14441d5cd
6 changed files with 108 additions and 121 deletions

View File

@@ -15,12 +15,10 @@
package vhost
import (
"bufio"
"bytes"
"fmt"
"io"
"net"
"net/http"
"strings"
"sync"
"time"
@@ -99,7 +97,6 @@ func (v *VhostMuxer) handle(c *conn.Conn) {
}
name = strings.ToLower(name)
l, ok := v.getListener(name)
if !ok {
return
@@ -113,28 +110,6 @@ func (v *VhostMuxer) handle(c *conn.Conn) {
l.accept <- c
}
type HttpMuxer struct {
*VhostMuxer
}
func GetHttpHostname(c *conn.Conn) (_ net.Conn, routerName string, err error) {
sc, rd := newShareConn(c.TcpConn)
request, err := http.ReadRequest(bufio.NewReader(rd))
if err != nil {
return sc, "", err
}
routerName = request.Host
request.Body.Close()
return sc, routerName, nil
}
func NewHttpMuxer(listener *conn.Listener, timeout time.Duration) (*HttpMuxer, error) {
mux, err := NewVhostMuxer(listener, GetHttpHostname, timeout)
return &HttpMuxer{mux}, err
}
type Listener struct {
name string
mux *VhostMuxer // for closing VhostMuxer