Files
kubeshark/tap/tlstapper/tls_reader.go
M. Mert Yıldıran 308fa78955 TRA-4383 Calculate request and response sizes and display them instead of BodySize field (#897)
* Define `ReadProgress` struct and update `Dissector` interface such that the `bufio.Reader` progress can be learned on item emitting

* Display the `requestSize` and `responseSize` fields in the UI

* Update the tests

* publish ui-common version 1.0.130 and bump to this version in ui/package.json file

Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com>
Co-authored-by: Roee Gadot <roee.gadot@up9.com>
2022-03-21 19:34:59 +02:00

46 lines
669 B
Go

package tlstapper
import (
"io"
"time"
"github.com/up9inc/mizu/tap/api"
)
type tlsReader struct {
key string
chunks chan *tlsChunk
data []byte
doneHandler func(r *tlsReader)
progress *api.ReadProgress
}
func (r *tlsReader) Read(p []byte) (int, error) {
var chunk *tlsChunk
for len(r.data) == 0 {
var ok bool
select {
case chunk, ok = <-r.chunks:
if !ok {
return 0, io.EOF
}
r.data = chunk.getRecordedData()
case <-time.After(time.Second * 3):
r.doneHandler(r)
return 0, io.EOF
}
if len(r.data) > 0 {
break
}
}
l := copy(p, r.data)
r.data = r.data[l:]
r.progress.Feed(l)
return l, nil
}