chore: rename HttpPacket to HttpRequest

This commit is contained in:
xvzc 2024-08-22 13:05:19 +09:00
parent d97d4e483c
commit 9beb9f8390
4 changed files with 15 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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()