refactor: separate core components and improve session & server handling

This commit is contained in:
2025-02-06 22:14:13 +07:00
parent dc219e2f7f
commit 8a1604fde8
9 changed files with 556 additions and 287 deletions

50
proto/proto.go Normal file
View File

@ -0,0 +1,50 @@
/*
Package proto provides byte-level interaction with HTTP request payload.
Example of HTTP payload for future references, new line symbols escaped:
POST /upload HTTP/1.1\r\n
User-Agent: Gor\r\n
Content-Length: 11\r\n
\r\n
Hello world
GET /index.html HTTP/1.1\r\n
User-Agent: Gor\r\n
\r\n
\r\n
https://github.com/buger/goreplay/blob/master/proto/proto.go
*/
package proto
import (
"bytes"
"net/http"
)
var Methods = [...]string{
http.MethodConnect, http.MethodDelete, http.MethodGet,
http.MethodHead, http.MethodOptions, http.MethodPatch,
http.MethodPost, http.MethodPut, http.MethodTrace,
}
func Method(payload []byte) []byte {
end := bytes.IndexByte(payload, ' ')
if end == -1 {
return nil
}
return payload[:end]
}
func IsHttpRequest(payload []byte) bool {
method := string(Method(payload))
var methodFound bool
for _, m := range Methods {
if methodFound = method == m; methodFound {
break
}
}
return methodFound
}