mirror of https://github.com/Dreamacro/clash.git
27 lines
703 B
Go
27 lines
703 B
Go
package inbound
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/netip"
|
|
"strconv"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
"github.com/Dreamacro/clash/context"
|
|
)
|
|
|
|
// NewHTTPS receive CONNECT request and return ConnContext
|
|
func NewHTTPS(request *http.Request, conn net.Conn) *context.ConnContext {
|
|
metadata := parseHTTPAddr(request)
|
|
metadata.Type = C.HTTPCONNECT
|
|
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
|
|
metadata.SrcIP = ip
|
|
metadata.SrcPort = port
|
|
}
|
|
if addrPort, err := netip.ParseAddrPort(conn.LocalAddr().String()); err == nil {
|
|
metadata.OriginDst = addrPort
|
|
metadata.InboundPort = strconv.Itoa(int(addrPort.Port()))
|
|
}
|
|
return context.NewConnContext(conn, metadata)
|
|
}
|