i would like to track the data usage of my app, but to do that, I need to be able to get the full size of an HttpUriRequest
and HttpResponse
. Simply getting the size of the HttpEntity
isn't enough because both the request and response have more data being transferred (headers, params, the actual URL being transmitted, etc). So, is there a way to find the full amount of data that's being transmitted both ways?
Thanks.
If you just want metrics "afterwards" you can just supply your own subclass of a suitable
ClientConnectionManager
implementation and fetch the relevantHttpConnectionMetrics
after the request is returned to the manager.As a simple (and slighty sh*tty) example, subclass
SingleClientConnManager
, like so:and just cram it into your HTTP client like so:
Edit: Alternative example that uses logging session input & output buffers alongside a mangled wire log + adding a listener interface.
Usage is very similar, but now with wire updates as stuff is sent: