Repository navigation
List the messages of a WebSocket and of an event stream - #12
Merged
Merged
Conversation
A WebSocket upgrade used to end the call at once. The capture now wraps the detached socket and reads the frames in both directions, joining fragments, decompressing permessage-deflate messages and listing ping, pong and close frames as messages of their own. The call stays open until both sides have said goodbye, the other side stops sending, or the socket is destroyed or fails, and it keeps going when the app closes the client that opened it. A text/event-stream response is parsed as it arrives, one event per blank line. Either way a call keeps the latest thousand messages and a megabyte of payload, applies the redaction to text, and counts all of them. The address of a WebSocket is recorded as the app wrote it, with ws or wss.
The memory budget counts them, a finished call writes them next to its bodies in a file of its own, a restart finds them again, and they are released and read back with the bodies. A line a crash left damaged is skipped.
A Messages or Events tab lists each message with its direction, kind, size and the moment it crossed, filters by direction, follows the newest while the call runs, and opens a message in the viewer that fits its payload. The list badges the call, the overview counts it, and a WebSocket is not offered for sending again. English and Italian.
HAR carries a WebSocket as Chrome does, with the opcode of each frame, and the events of a stream under their own key. The text export lists them with their direction and offset.
|
This pull request adds no capability the code did not already have. 38 files read · 2653 ms · against |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A WebSocket used to end its call as soon as the upgrade went through, and an event stream was one long response body. Both are now conversations: the call stays open, lists its messages as they cross, and gets a Messages or Events tab.
WebSockets. The capture wraps the socket that
dart:iodetaches after the handshake and reads the frames of both directions from the bytes that cross it. Fragmented messages are joined,permessage-deflatemessages are decompressed (with or without a window kept between messages, as the handshake agreed), and ping, pong and close frames are listed as messages of their own. A reader that meets bytes it cannot make sense of stops and says nothing more, and it never changes what the app reads or writes. The call ends when both sides have sent a close frame, when the other side stops sending, when the socket is destroyed or when it fails. It is not cancelled when the app closes the client that opened it, which apps do once the handshake is over.Event streams. A
text/event-streamresponse is parsed as it arrives, by the rules of the HTML standard, and each complete event becomes a message. The raw stream is still the body of the response.What a call keeps. The latest thousand messages and a megabyte of payload, each message cut at
maxBodyBytes, with the real size and the count of everything that came before. Text goes through the redaction like a body does. The address of a WebSocket is recorded as the app wrote it,wss://host/path, and not as the HTTP request the handshake is.Where it shows:
_webSocketMessagesthe way Chrome writes it and_eventSourceMessagesfor streams, and the text export.A WebSocket is not offered for sending again, because its handshake is not a request that stands alone.
One limit, written in the package README:
dart:iomakes one client for every WebSocket the first time one is opened, so a WebSocket opened beforeFlutwire.initis not seen. On the web nothing is recorded, because the browser opens WebSockets itself.I tried it on an Android emulator with the example app, which has a new Streams section: a WebSocket against an echo server, with text, JSON and binary messages and the close frame, and an event stream from a public feed. All four suites pass,
flutter analyze --fatal-infosis clean and the example builds for the web.Targets
0.2.0, Tier 2, M16.