github.com/igoogolx/clash@v1.19.8/adapter/inbound/http.go (about)

     1  package inbound
     2  
     3  import (
     4  	"net"
     5  	"net/netip"
     6  
     7  	C "github.com/igoogolx/clash/constant"
     8  	"github.com/igoogolx/clash/context"
     9  	"github.com/igoogolx/clash/transport/socks5"
    10  )
    11  
    12  // NewHTTP receive normal http request and return HTTPContext
    13  func NewHTTP(target socks5.Addr, source net.Addr, originTarget net.Addr, conn net.Conn) *context.ConnContext {
    14  	metadata := parseSocksAddr(target)
    15  	metadata.NetWork = C.TCP
    16  	metadata.Type = C.HTTP
    17  	if ip, port, err := parseAddr(source); err == nil {
    18  		metadata.SrcIP = ip
    19  		metadata.SrcPort = C.Port(port)
    20  	}
    21  	if originTarget != nil {
    22  		if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
    23  			metadata.OriginDst = addrPort
    24  		}
    25  	}
    26  	return context.NewConnContext(conn, metadata)
    27  }