mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package proxy
|
|
|
|
import (
|
|
"context"
|
|
"github.com/xvzc/SpoofDPI/util"
|
|
"net"
|
|
"strconv"
|
|
|
|
"github.com/xvzc/SpoofDPI/util/log"
|
|
|
|
"github.com/xvzc/SpoofDPI/packet"
|
|
)
|
|
|
|
const protoHTTP = "HTTP"
|
|
|
|
func (pxy *Proxy) handleHttp(ctx context.Context, lConn *net.TCPConn, pkt *packet.HttpRequest, ip string) {
|
|
ctx = util.GetCtxWithScope(ctx, protoHTTP)
|
|
logger := log.GetCtxLogger(ctx)
|
|
|
|
pkt.Tidy()
|
|
|
|
// Create a connection to the requested server
|
|
var port int = 80
|
|
var err error
|
|
if pkt.Port() != "" {
|
|
port, err = strconv.Atoi(pkt.Port())
|
|
if err != nil {
|
|
logger.Debug().Msgf("error while parsing port for %s aborting..", pkt.Domain())
|
|
}
|
|
}
|
|
|
|
rConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.ParseIP(ip), Port: port})
|
|
if err != nil {
|
|
lConn.Close()
|
|
logger.Debug().Msgf("%s", err)
|
|
return
|
|
}
|
|
|
|
logger.Debug().Msgf("new connection to the server %s -> %s", rConn.LocalAddr(), pkt.Domain())
|
|
|
|
go Serve(ctx, rConn, lConn, protoHTTP, pkt.Domain(), lConn.RemoteAddr().String(), pxy.timeout)
|
|
|
|
_, err = rConn.Write(pkt.Raw())
|
|
if err != nil {
|
|
logger.Debug().Msgf("error sending request to %s: %s", pkt.Domain(), err)
|
|
return
|
|
}
|
|
|
|
logger.Debug().Msgf("sent a request to %s", pkt.Domain())
|
|
|
|
go Serve(ctx, lConn, rConn, protoHTTP, lConn.RemoteAddr().String(), pkt.Domain(), pxy.timeout)
|
|
}
|