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