diff --git a/proxy/proxy.go b/proxy/proxy.go index dc0c76f..432bd22 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -38,7 +38,7 @@ func Start() { util.Debug("Client sent data: ", len(b)) - r := request.New(&b) + r := request.NewHttpRequest(&b) if !r.IsValidMethod() { log.Println("Unsupported method: ", r.Method) diff --git a/request/http.go b/request/http.go index a109e1b..283381b 100644 --- a/request/http.go +++ b/request/http.go @@ -4,13 +4,21 @@ import ( "strings" ) -type Request struct { +type HttpRequest struct { Raw *[]byte Method string Domain string } -func (r *Request) IsValidMethod() bool { +func NewHttpRequest(raw *[]byte) HttpRequest { + return HttpRequest{ + Raw: raw, + Method: extractMethod(raw), + Domain: extractDomain(raw), + } +} + +func (r *HttpRequest) IsValidMethod() bool { if _, exists := getValidMethods()[r.Method]; exists { return true } @@ -18,15 +26,7 @@ func (r *Request) IsValidMethod() bool { return false } -func New(raw *[]byte) Request { - return Request{ - Raw: raw, - Method: extractMethod(raw), - Domain: extractDomain(raw), - } -} - -func (r *Request) ToChunks() { +func (r *HttpRequest) ToChunks() { } diff --git a/request/https.go b/request/https.go new file mode 100644 index 0000000..2ff34bc --- /dev/null +++ b/request/https.go @@ -0,0 +1,19 @@ +package request + +type HttpsRequest struct { + Raw *[]byte +} + +func NewHttpsRequest(raw *[]byte) HttpsRequest { + return HttpsRequest{ + Raw: raw, + } +} + +func (r HttpsRequest) SplitInChunks() [][]byte { + if len(*r.Raw) < 1 { + return [][]byte{*r.Raw} + } + + return [][]byte{(*r.Raw)[:1], (*r.Raw)[1:]} +}