mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-04 13:24:46 +00:00
108 lines
1.9 KiB
Go
108 lines
1.9 KiB
Go
package request
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type HttpRequest struct {
|
|
Raw *[]byte
|
|
Method string
|
|
Domain string
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (r *HttpRequest) ToChunks() {
|
|
|
|
}
|
|
|
|
func extractDomain(request *[]byte) string {
|
|
i := 0
|
|
for ; i < len(*request); i++ {
|
|
if (*request)[i] == ' ' {
|
|
i++
|
|
break
|
|
}
|
|
}
|
|
|
|
j := i
|
|
for ; j < len(*request); j++ {
|
|
if (*request)[j] == ' ' {
|
|
break
|
|
}
|
|
}
|
|
|
|
domain := string((*request)[i:j])
|
|
domain = strings.Replace(domain, "http://", "", 1)
|
|
domain = strings.Replace(domain, "https://", "", 1)
|
|
domain = strings.Split(domain, ":")[0]
|
|
domain = strings.Split(domain, "/")[0]
|
|
|
|
return strings.TrimSpace(domain)
|
|
}
|
|
|
|
func extractMethod(message *[]byte) string {
|
|
i := 0
|
|
for ; i < len(*message); i++ {
|
|
if (*message)[i] == ' ' {
|
|
break
|
|
}
|
|
}
|
|
|
|
method := strings.TrimSpace(string((*message)[:i]))
|
|
|
|
return strings.ToUpper(method)
|
|
}
|
|
|
|
func getValidMethods() map[string]struct{} {
|
|
return map[string]struct{}{
|
|
"DELETE": {},
|
|
"GET": {},
|
|
"HEAD": {},
|
|
"POST": {},
|
|
"PUT": {},
|
|
"CONNECT": {},
|
|
"OPTIONS": {},
|
|
"TRACE": {},
|
|
"COPY": {},
|
|
"LOCK": {},
|
|
"MKCOL": {},
|
|
"MOVE": {},
|
|
"PROPFIND": {},
|
|
"PROPPATCH": {},
|
|
"SEARCH": {},
|
|
"UNLOCK": {},
|
|
"BIND": {},
|
|
"REBIND": {},
|
|
"UNBIND": {},
|
|
"ACL": {},
|
|
"REPORT": {},
|
|
"MKACTIVITY": {},
|
|
"CHECKOUT": {},
|
|
"MERGE": {},
|
|
"M-SEARCH": {},
|
|
"NOTIFY": {},
|
|
"SUBSCRIBE": {},
|
|
"UNSUBSCRIBE": {},
|
|
"PATCH": {},
|
|
"PURGE": {},
|
|
"MKCALENDAR": {},
|
|
"LINK": {},
|
|
"UNLINK": {},
|
|
}
|
|
}
|