Compress if it's gzip chunk (probably wrong!)

This commit is contained in:
M. Mert Yildiran 2022-06-02 03:11:42 +03:00
parent 308d3cfd87
commit 094a7c3da4
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A

View File

@ -3,6 +3,7 @@ package tlstapper
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"compress/gzip"
"fmt" "fmt"
"log" "log"
"sync" "sync"
@ -161,8 +162,22 @@ func (p *tlsPoller) pollGolangReadWrite(rd *ringbuf.Reader, emitter api.Emitter,
connection = _connection.(*golangConnection) connection = _connection.(*golangConnection)
} }
data := []byte(b.Data[:])
if b.IsGzipChunk { if b.IsGzipChunk {
// Compress if it's gzip chunk (probably wrong!)
connection.Gzipped = true connection.Gzipped = true
var buf bytes.Buffer
gz := gzip.NewWriter(&buf)
if _, err := gz.Write(data); err != nil {
log.Printf("gzip write: %s", err)
continue
}
if err := gz.Close(); err != nil {
log.Printf("gzip close: %s", err)
continue
}
data = buf.Bytes()
} }
if b.IsRequest { if b.IsRequest {
@ -184,12 +199,12 @@ func (p *tlsPoller) pollGolangReadWrite(rd *ringbuf.Reader, emitter api.Emitter,
go dissect(p.extension, connection.ClientReader, options) go dissect(p.extension, connection.ClientReader, options)
go dissect(p.extension, connection.ServerReader, options) go dissect(p.extension, connection.ServerReader, options)
request := make([]byte, len(b.Data[:b.Len])) request := make([]byte, len(data[:b.Len]))
copy(request, b.Data[:b.Len]) copy(request, data[:b.Len])
connection.ClientReader.send(request) connection.ClientReader.send(request)
} else { } else {
response := make([]byte, len(b.Data[:b.Len])) response := make([]byte, len(data[:b.Len]))
copy(response, b.Data[:b.Len]) copy(response, data[:b.Len])
connection.ServerReader.send(response) connection.ServerReader.send(response)
} }
} }