mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Benchmarking, packaging, and fix issues, tests and perfomance (#797)
### performance - handling of the very big packet(any size that can be buffered) - speeding up TCP sessions by using message hints: Added **proto.HasFullPayload** that helps to validate the entire HTTP request, it supports `Chunked` encoding too! Added **proto.HasRequestTitle** and **proto.HasResponseTitle** for validating the beginning of HTTP request. Those methods are used `input_raw.go` with `TCP`. - supports Keep-Alive: the above functions helps to support keep-alive ### Packaging - **capture:** engines(capture/doc.go) - **tcp:** tcp message parser (tcp/doc.go) ### benchmarking - **capture.BenchmarkPcapDump:** the benchmarks regarding dumping packets in a pcap file - **capture.BenchmarkPcapFile:** the benchmarks of reading packets from a pcap file - **capture.BenchmarkPcap:** the benchmarks of parsing packets from the loopback interface with pcap handles - **proto.BenchmarkHasFullPayload:**: benchmarking this function which validates the HTTP payload - **tcp.BenchmarkPacketParseAndSort:** benchmarks of parsing and sorting packets - **tcp.BenchmarkMessageParserWithoutHint:** benchmarks of message reasembling by using `SYN` and `FIN` flag - **tcp.BenchmarkMessageParserWithHint:** benchmarks of message reasembling by using `proto.HasRequestTitle` and `proto.HasFullPayload` flag ### issues see linked issues ### tests - fixed input raw and engine tests **Most of the changed of the files, was about using functionalities of** `tcp` **and** `capture` **in existing functionalities**
This commit is contained in:
+10
-10
@@ -15,9 +15,9 @@ type HTTPModifier struct {
|
||||
|
||||
func NewHTTPModifier(config *HTTPModifierConfig) *HTTPModifier {
|
||||
// Optimization to skip modifier completely if we do not need it
|
||||
if len(config.UrlRegexp) == 0 &&
|
||||
len(config.UrlNegativeRegexp) == 0 &&
|
||||
len(config.UrlRewrite) == 0 &&
|
||||
if len(config.URLRegexp) == 0 &&
|
||||
len(config.URLNegativeRegexp) == 0 &&
|
||||
len(config.URLRewrite) == 0 &&
|
||||
len(config.HeaderRewrite) == 0 &&
|
||||
len(config.HeaderFilters) == 0 &&
|
||||
len(config.HeaderNegativeFilters) == 0 &&
|
||||
@@ -34,7 +34,7 @@ func NewHTTPModifier(config *HTTPModifierConfig) *HTTPModifier {
|
||||
}
|
||||
|
||||
func (m *HTTPModifier) Rewrite(payload []byte) (response []byte) {
|
||||
if !proto.IsHTTPPayload(payload) {
|
||||
if !proto.HasRequestTitle(payload) {
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -67,12 +67,12 @@ func (m *HTTPModifier) Rewrite(payload []byte) (response []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.config.UrlRegexp) > 0 {
|
||||
if len(m.config.URLRegexp) > 0 {
|
||||
path := proto.Path(payload)
|
||||
|
||||
matched := false
|
||||
|
||||
for _, f := range m.config.UrlRegexp {
|
||||
for _, f := range m.config.URLRegexp {
|
||||
if f.regexp.Match(path) {
|
||||
matched = true
|
||||
break
|
||||
@@ -84,10 +84,10 @@ func (m *HTTPModifier) Rewrite(payload []byte) (response []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.config.UrlNegativeRegexp) > 0 {
|
||||
if len(m.config.URLNegativeRegexp) > 0 {
|
||||
path := proto.Path(payload)
|
||||
|
||||
for _, f := range m.config.UrlNegativeRegexp {
|
||||
for _, f := range m.config.URLNegativeRegexp {
|
||||
if f.regexp.Match(path) {
|
||||
return
|
||||
}
|
||||
@@ -165,10 +165,10 @@ func (m *HTTPModifier) Rewrite(payload []byte) (response []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.config.UrlRewrite) > 0 {
|
||||
if len(m.config.URLRewrite) > 0 {
|
||||
path := proto.Path(payload)
|
||||
|
||||
for _, f := range m.config.UrlRewrite {
|
||||
for _, f := range m.config.URLRewrite {
|
||||
if f.src.Match(path) {
|
||||
path = f.src.ReplaceAll(path, f.target)
|
||||
payload = proto.SetPath(payload, path)
|
||||
|
||||
Reference in New Issue
Block a user