twitter/CocoaSPDY — pull request #60 by kgoodier (2014-09-11 06:36:20+00:00)
Title: Expose bytes transmitted and received for each stream

There are 2 parts to this change.

One is to track each byte sent and received on the socket and attribute them to a stream, including all frame and content sizes. This required changes to the encoder & decoder & session code. Protocol-level messages are not accounted for.

The other is to expose this data to the application. The existing metadata solution was insufficient since it was provided in the response headers, which are returned to the application after the response headers are read but before the body is read. Clearly this doesn't work, and since the final "connectionDidFinishLoading" callback has no extension mechanism, I had to introduce a new SPDY-specific delegate. The app can register this delegate in the NSURLRequest object (as a category property), and it will be called just prior to the connectionDidFinishLoading callback. The metadata is provided in this callback.

Since the SPDYSession needs to collect the metadata but let the SPDYStream make the callback, some of the code in the session that manages the final lifetime of a stream had to be refactored. A few other potential bugs were also fixed there. See commit description for more details.