diff options
author | Emiliano Ciavatta | 2020-09-16 15:49:50 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-09-16 15:49:50 +0000 |
commit | dfd6d543074b4a30c2fc990063ca69ebf8a734e1 (patch) | |
tree | a022ad9861b35c38ad1d0945d79470adfe26ae52 /connection_streams_controller.go | |
parent | ec949ffea86a14526a7142d048022a4a07f684ff (diff) |
Fix body decoding bugs. Improve frontend
Diffstat (limited to 'connection_streams_controller.go')
-rw-r--r-- | connection_streams_controller.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/connection_streams_controller.go b/connection_streams_controller.go index c4876b1..9d73b0e 100644 --- a/connection_streams_controller.go +++ b/connection_streams_controller.go @@ -93,7 +93,7 @@ func (csc ConnectionStreamsController) GetConnectionPayload(c context.Context, c if clientBlocksIndex < len(clientStream.BlocksIndexes)-1 { end = clientStream.BlocksIndexes[clientBlocksIndex+1] } else { - end = len(clientStream.Payload) - 1 + end = len(clientStream.Payload) } size := uint64(end - start) @@ -117,7 +117,7 @@ func (csc ConnectionStreamsController) GetConnectionPayload(c context.Context, c if serverBlocksIndex < len(serverStream.BlocksIndexes)-1 { end = serverStream.BlocksIndexes[serverBlocksIndex+1] } else { - end = len(serverStream.Payload) - 1 + end = len(serverStream.Payload) } size := uint64(end - start) @@ -137,7 +137,18 @@ func (csc ConnectionStreamsController) GetConnectionPayload(c context.Context, c sideChanged, lastClient, lastServer = lastClient, false, true } - if sideChanged { + if !hasClientBlocks() { + clientDocumentIndex++ + clientBlocksIndex = 0 + clientStream = csc.getConnectionStream(c, connectionID, true, clientDocumentIndex) + } + if !hasServerBlocks() { + serverDocumentIndex++ + serverBlocksIndex = 0 + serverStream = csc.getConnectionStream(c, connectionID, false, serverDocumentIndex) + } + + updateMetadata := func() { metadata := parsers.Parse(contentChunkBuffer.Bytes()) var isMetadataContinuation bool for _, elem := range payloadsBuffer { @@ -149,28 +160,26 @@ func (csc ConnectionStreamsController) GetConnectionPayload(c context.Context, c payloadsBuffer = payloadsBuffer[:0] contentChunkBuffer.Reset() } + + if sideChanged { + updateMetadata() + } payloadsBuffer = append(payloadsBuffer, payload) contentChunkBuffer.Write(lastContentSlice) + if clientStream.ID.IsZero() && serverStream.ID.IsZero() { + updateMetadata() + } + if globalIndex > format.Skip { // problem: waste of time if the payload is discarded payloads = append(payloads, payload) } if globalIndex > format.Skip+format.Limit { // problem: the last chunk is not parsed, but can be ok because it is not finished + updateMetadata() return payloads } - - if !hasClientBlocks() { - clientDocumentIndex++ - clientBlocksIndex = 0 - clientStream = csc.getConnectionStream(c, connectionID, true, clientDocumentIndex) - } - if !hasServerBlocks() { - serverDocumentIndex++ - serverBlocksIndex = 0 - serverStream = csc.getConnectionStream(c, connectionID, false, serverDocumentIndex) - } } return payloads |