Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly update ContentLength for uncompressed response body #498

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/event_processor/http_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,15 @@ func (hr *HTTPResponse) Display() []byte {
log.Println(err)
break
}
gbuf, err := io.ReadAll(reader)
if err != nil {
log.Println(err)
break
}

hr.response.Body = io.NopCloser(bytes.NewReader(gbuf))
// gzip uncompressed success
hr.response.Body = reader
hr.response.ContentLength = int64(len(gbuf))
hr.packerType = PacketTypeGzip
defer reader.Close()
default:
Expand Down
20 changes: 17 additions & 3 deletions pkg/event_processor/processor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package event_processor

import (
"bytes"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -30,6 +31,8 @@ type SSLDataEventTmp struct {
func TestEventProcessor_Serve(t *testing.T) {

logger := log.Default()
var buf bytes.Buffer
logger.SetOutput(&buf)
/*
f, e := os.Create("./output.log")
if e != nil {
Expand Down Expand Up @@ -68,12 +71,23 @@ func TestEventProcessor_Serve(t *testing.T) {
}

tick := time.NewTicker(time.Second * 3)
select {
case <-tick.C:
}
<-tick.C

err = ep.Close()
lines = strings.Split(buf.String(), "\n")
ok := true
for _, line := range lines {
if strings.Contains(strings.ToLower(line), "dump") {
cfc4n marked this conversation as resolved.
Show resolved Hide resolved
t.Log(line)
ok = false
}
}
if err != nil {
t.Fatalf("close error: %s", err.Error())
}
if !ok {
t.Fatalf("some errors occurred")
}
t.Log(buf.String())
t.Log("done")
}
7 changes: 7 additions & 0 deletions pkg/event_processor/testdata/952253698000000.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET / HTTP/1.1
Host: www.baidu.com
User-Agent: Wget/1.21.2
Accept: */*
Accept-Encoding: gzip
Connection: Keep-Alive

7 changes: 7 additions & 0 deletions pkg/event_processor/testdata/952253698001000.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 1145
Server: bfe
Date: Fri, 01 Mar 2024 08:24:27 GMT
Content-Type: text/html;charset=UTF-8

Binary file added pkg/event_processor/testdata/952253698002000.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/event_processor/testdata/952282712204824.bin
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu)
Date: Wed, 29 Jun 2022 09:44:35 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 74332
Content-Length: 20124
cfc4n marked this conversation as resolved.
Show resolved Hide resolved
Connection: keep-alive
Vary: Accept-Encoding, Cookie
Cache-Control: max-age=3, must-revalidate
Expand Down
3 changes: 3 additions & 0 deletions pkg/event_processor/testdata/all.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{"DataType":1,"Timestamp":952253291192473,"Pid":469929,"Tid":469929,"DataLen":240,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":0,"Timestamp":952253597324253,"Pid":469929,"Tid":469929,"DataLen":308,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":0,"Timestamp":952253597628796,"Pid":469929,"Tid":469929,"DataLen":191,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":1,"Timestamp":952253698000000,"Pid":469930,"Tid":469930,"DataLen":124,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":0,"Timestamp":952253698001000,"Pid":469930,"Tid":469930,"DataLen":154,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":0,"Timestamp":952253698002000,"Pid":469930,"Tid":469930,"DataLen":1145,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771}
{"DataType":1,"Timestamp":952282673103459,"Pid":469953,"Tid":469953,"DataLen":77,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771}
{"DataType":0,"Timestamp":952282712204824,"Pid":469953,"Tid":469953,"DataLen":4096,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771}
{"DataType":0,"Timestamp":952282715334491,"Pid":469953,"Tid":469953,"DataLen":4096,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771}
Expand Down
Loading