add sni connector

This commit is contained in:
ginuerzh
2021-11-26 17:20:10 +08:00
parent 5b97b878fb
commit efbabd4052
14 changed files with 370 additions and 56 deletions

View File

@ -15,6 +15,7 @@ import (
"strings"
"time"
"github.com/asaskevich/govalidator"
"github.com/go-gost/gost/pkg/bypass"
"github.com/go-gost/gost/pkg/chain"
"github.com/go-gost/gost/pkg/handler"
@ -59,12 +60,10 @@ func (h *httpHandler) Handle(ctx context.Context, conn net.Conn) {
defer conn.Close()
start := time.Now()
h.logger = h.logger.WithFields(map[string]interface{}{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
})
h.logger.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
defer func() {
h.logger.WithFields(map[string]interface{}{
@ -87,6 +86,10 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
return
}
if h.md.sni && !req.URL.IsAbs() && govalidator.IsDNSName(req.Host) {
req.URL.Scheme = "http"
}
// Try to get the actual host.
// Compatible with GOST 2.x.
if v := req.Header.Get("Gost-Target"); v != "" {