From 9beb9f839032cb55be0c62f2b3d15cc6e4c5cd3c Mon Sep 17 00:00:00 2001 From: xvzc Date: Thu, 22 Aug 2024 13:05:19 +0900 Subject: [PATCH] chore: rename HttpPacket to HttpRequest --- packet/http.go | 24 ++++++++++++------------ proxy/http.go | 2 +- proxy/https.go | 2 +- proxy/proxy.go | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packet/http.go b/packet/http.go index 868099e..ea86b1a 100644 --- a/packet/http.go +++ b/packet/http.go @@ -44,7 +44,7 @@ var validMethod = map[string]struct{}{ "UNLINK": {}, } -type HttpPacket struct { +type HttpRequest struct { raw []byte method string domain string @@ -53,7 +53,7 @@ type HttpPacket struct { version string } -func ReadHttpPacket(rdr io.Reader) (*HttpPacket, error) { +func ReadHttpRequest(rdr io.Reader) (*HttpRequest, error) { p, err := parse(rdr) if err != nil { return nil, err @@ -62,26 +62,26 @@ func ReadHttpPacket(rdr io.Reader) (*HttpPacket, error) { return p, nil } -func (p *HttpPacket) Raw() []byte { +func (p *HttpRequest) Raw() []byte { return p.raw } -func (p *HttpPacket) Method() string { +func (p *HttpRequest) Method() string { return p.method } -func (p *HttpPacket) Domain() string { +func (p *HttpRequest) Domain() string { return p.domain } -func (p *HttpPacket) Port() string { +func (p *HttpRequest) Port() string { return p.port } -func (p *HttpPacket) Version() string { +func (p *HttpRequest) Version() string { return p.version } -func (p *HttpPacket) IsValidMethod() bool { +func (p *HttpRequest) IsValidMethod() bool { if _, exists := validMethod[p.Method()]; exists { return true } @@ -89,11 +89,11 @@ func (p *HttpPacket) IsValidMethod() bool { return false } -func (p *HttpPacket) IsConnectMethod() bool { +func (p *HttpRequest) IsConnectMethod() bool { return p.Method() == "CONNECT" } -func (p *HttpPacket) Tidy() { +func (p *HttpRequest) Tidy() { s := string(p.raw) lines := strings.Split(s, "\r\n") @@ -121,7 +121,7 @@ func (p *HttpPacket) Tidy() { p.raw = []byte(result) } -func parse(rdr io.Reader) (*HttpPacket, error) { +func parse(rdr io.Reader) (*HttpRequest, error) { sb := strings.Builder{} tee := io.TeeReader(rdr, &sb) request, err := http.ReadRequest(bufio.NewReader(tee)) @@ -129,7 +129,7 @@ func parse(rdr io.Reader) (*HttpPacket, error) { return nil, err } - p := &HttpPacket{} + p := &HttpRequest{} p.raw = []byte(sb.String()) p.domain, p.port, err = net.SplitHostPort(request.Host) diff --git a/proxy/http.go b/proxy/http.go index 97944aa..962a40f 100644 --- a/proxy/http.go +++ b/proxy/http.go @@ -9,7 +9,7 @@ import ( "github.com/xvzc/SpoofDPI/packet" ) -func (pxy *Proxy) handleHttp(lConn *net.TCPConn, pkt *packet.HttpPacket, ip string) { +func (pxy *Proxy) handleHttp(lConn *net.TCPConn, pkt *packet.HttpRequest, ip string) { pkt.Tidy() // Create a connection to the requested server diff --git a/proxy/https.go b/proxy/https.go index efc4163..8c76651 100644 --- a/proxy/https.go +++ b/proxy/https.go @@ -8,7 +8,7 @@ import ( "github.com/xvzc/SpoofDPI/packet" ) -func (pxy *Proxy) handleHttps(lConn *net.TCPConn, exploit bool, initPkt *packet.HttpPacket, ip string) { +func (pxy *Proxy) handleHttps(lConn *net.TCPConn, exploit bool, initPkt *packet.HttpRequest, ip string) { // Create a connection to the requested server var port int = 443 var err error diff --git a/proxy/proxy.go b/proxy/proxy.go index c2beec6..180b975 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -59,7 +59,7 @@ func (pxy *Proxy) Start() { } go func() { - pkt, err := packet.ReadHttpPacket(conn) + pkt, err := packet.ReadHttpRequest(conn) if err != nil { log.Debug("[PROXY] error while parsing request: ", err) conn.Close()