mihomo/adapter/inbound/http.go

32 lines
930 B
Go
Raw Normal View History

2019-12-08 12:17:24 +08:00
package inbound
import (
2018-08-11 22:51:30 +08:00
"net"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/context"
2021-06-15 17:13:40 +08:00
"github.com/Dreamacro/clash/transport/socks5"
)
2021-04-29 11:23:14 +08:00
// NewHTTP receive normal http request and return HTTPContext
func NewHTTP(target socks5.Addr, source net.Addr, conn net.Conn) *context.ConnContext {
2022-12-04 13:37:14 +08:00
return NewHTTPWithInfos(target, source, conn, "", "")
}
2022-12-04 22:08:20 +08:00
func NewHTTPWithInfos(target socks5.Addr, source net.Addr, conn net.Conn, inName, specialRules string) *context.ConnContext {
metadata := parseSocksAddr(target)
2021-06-15 17:13:40 +08:00
metadata.NetWork = C.TCP
metadata.Type = C.HTTP
2022-12-04 13:37:14 +08:00
metadata.InName = inName
2022-12-04 22:08:20 +08:00
metadata.SpecialRules = specialRules
2021-06-15 17:13:40 +08:00
if ip, port, err := parseAddr(source.String()); err == nil {
2019-05-09 21:00:29 +08:00
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-06-15 17:13:40 +08:00
return context.NewConnContext(conn, metadata)
2021-03-10 16:23:19 +08:00
}