mihomo/adapter/inbound/https.go

28 lines
690 B
Go
Raw Permalink Normal View History

2019-12-08 12:17:24 +08:00
package inbound
2018-08-27 00:06:40 +08:00
import (
"net"
"net/http"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/context"
2018-08-27 00:06:40 +08:00
)
2021-04-29 11:23:14 +08:00
// NewHTTPS receive CONNECT request and return ConnContext
func NewHTTPS(request *http.Request, conn net.Conn, additions ...Addition) *context.ConnContext {
metadata := parseHTTPAddr(request)
metadata.Type = C.HTTPS
for _, addition := range additions {
addition.Apply(metadata)
}
2023-01-17 15:41:51 +08:00
if ip, port, err := parseAddr(conn.RemoteAddr()); err == nil {
2019-05-09 21:00:29 +08:00
metadata.SrcIP = ip
metadata.SrcPort = port
}
2023-01-17 15:41:51 +08:00
if ip, port, err := parseAddr(conn.LocalAddr()); err == nil {
2022-11-11 23:36:06 +08:00
metadata.InIP = ip
metadata.InPort = port
}
return context.NewConnContext(conn, metadata)
2018-08-27 00:06:40 +08:00
}