add https request

This commit is contained in:
xvzc 2022-01-08 03:01:54 +09:00
parent 81938445a1
commit b615f4aabc
3 changed files with 31 additions and 12 deletions

View File

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

View File

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

19
request/https.go Normal file
View File

@ -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:]}
}