2019-12-08 12:17:24 +08:00
|
|
|
package inbound
|
2018-08-27 00:06:40 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
2019-10-27 21:44:07 +08:00
|
|
|
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2021-01-23 14:49:46 +08:00
|
|
|
"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
|
2021-01-23 14:49:46 +08:00
|
|
|
func NewHTTPS(request *http.Request, conn net.Conn) *context.ConnContext {
|
2022-12-04 13:37:14 +08:00
|
|
|
return NewHTTPSWithInfos(request, conn, "", "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHTTPSWithInfos(request *http.Request, conn net.Conn, inName, preferRulesName string) *context.ConnContext {
|
2019-02-02 21:03:13 +08:00
|
|
|
metadata := parseHTTPAddr(request)
|
2022-05-20 23:17:16 +08:00
|
|
|
metadata.Type = C.HTTPS
|
2022-12-04 13:37:14 +08:00
|
|
|
metadata.PreferRulesName = preferRulesName
|
|
|
|
metadata.InName = inName
|
2019-05-09 21:00:29 +08:00
|
|
|
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
|
|
|
|
metadata.SrcIP = ip
|
|
|
|
metadata.SrcPort = port
|
|
|
|
}
|
2022-11-11 23:36:06 +08:00
|
|
|
if ip, port, err := parseAddr(conn.LocalAddr().String()); err == nil {
|
|
|
|
metadata.InIP = ip
|
|
|
|
metadata.InPort = port
|
|
|
|
}
|
2021-01-23 14:49:46 +08:00
|
|
|
return context.NewConnContext(conn, metadata)
|
2018-08-27 00:06:40 +08:00
|
|
|
}
|