Indicate http version used for connection/response
Request Statement
When receiving an http response from upstream server it would be really handy to know which http version served the response. E.g. http1.1 / http2
This is super handy to add to e.g. OTEL telemetry to understand how the responses are being server from upstream infrastructure.
Thank you!
Solution Brainstorm
Updating the ResponseBody with an extra parameter might be an ok place to put this. Its not really the body of the response, but it already has some non-body items in anyway....
Based on my knowledge, the protocol header with the HTTP version should be available in the response's header.
I am not sure about this.. in older protocols, http version was indicated in http status line. For http2 it is negotiated in tls handshake with ALPN.
If it were passed as a response header in dio, this would be a synthetic header?
For HTTP/1.x it's available in the raw header, but it's not publicly visible.
For H2 we have nothing available from the transport, unfortunately.
We seem to have no reliable method to inspect the protocol during the request and response. WDYT?
The http2 proto is handled by a separate code path, so it already knows that it is http2..
Can get the http1.x proto from status line - 99% it will be 1.1, and http2 (h2) can be hardcoded in the http2 handler? If the status line protocol version isn't available at all, it would still be ok to make distinction between http1.x and 2, as there are different code paths.
Then can be exposed in a way to make it public in the ResponseBody.
The http2 proto is handled by a separate code path, so it already knows that it is http2..
and http2 (h2) can be hardcoded in the http2 handler? If the status line protocol version isn't available at all, it would still be ok to make distinction between http1.x and 2, as there are different code paths.
If you don't access the adapter directly, you won't know if it's actually h2: https://github.com/cfug/dio/blob/30c1070e3ae21171d83abeadd7b425b7250dc9a8/plugins/http2_adapter/lib/src/http2_adapter.dart#L62-L69 The adapter will automatically retry with H1 if H2 is not available. So the result here doesn't make sense since it's just simply guessing.
Can get the http1.x proto from status line - 99% it will be 1.1,
This is also inaccessible with dart:io AFAIK.
Then can be exposed in a way to make it public in the ResponseBody.
We intend to place only necessary information in classes. To retrieve the protocol version, based on the above paths, you can guess the protocol version from what adapter you are using, and make a minimum override to the H2 adapter to be aware of the fallback behavior.