2019-12-08 12:17:24 +08:00
|
|
|
package inbound
|
2018-07-26 00:04:59 +08:00
|
|
|
|
|
|
|
import (
|
2018-08-11 22:51:30 +08:00
|
|
|
"net"
|
2023-06-13 23:25:32 +08:00
|
|
|
"net/netip"
|
2018-07-26 00:04:59 +08:00
|
|
|
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2021-01-23 14:49:46 +08:00
|
|
|
"github.com/Dreamacro/clash/context"
|
2021-06-15 17:13:40 +08:00
|
|
|
"github.com/Dreamacro/clash/transport/socks5"
|
2018-07-26 00:04:59 +08:00
|
|
|
)
|
|
|
|
|
2021-04-29 11:23:14 +08:00
|
|
|
// NewHTTP receive normal http request and return HTTPContext
|
2023-06-13 23:25:32 +08:00
|
|
|
func NewHTTP(target socks5.Addr, source net.Addr, originTarget net.Addr, conn net.Conn) *context.ConnContext {
|
2021-09-13 23:46:39 +08:00
|
|
|
metadata := parseSocksAddr(target)
|
2021-06-15 17:13:40 +08:00
|
|
|
metadata.NetWork = C.TCP
|
2019-10-27 21:44:07 +08:00
|
|
|
metadata.Type = C.HTTP
|
2023-08-03 23:20:40 +08:00
|
|
|
if ip, port, err := parseAddr(source); err == nil {
|
2019-05-09 21:00:29 +08:00
|
|
|
metadata.SrcIP = ip
|
2023-08-03 23:20:40 +08:00
|
|
|
metadata.SrcPort = C.Port(port)
|
2019-05-09 21:00:29 +08:00
|
|
|
}
|
2023-06-18 11:16:40 +08:00
|
|
|
if originTarget != nil {
|
|
|
|
if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
|
|
|
|
metadata.OriginDst = addrPort
|
|
|
|
}
|
2023-06-13 23:25:32 +08:00
|
|
|
}
|
2021-06-15 17:13:40 +08:00
|
|
|
return context.NewConnContext(conn, metadata)
|
2021-03-10 16:23:19 +08:00
|
|
|
}
|