-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose DoGet response headers & trailers #4727
feat: expose DoGet response headers & trailers #4727
Conversation
http = "0.2.9" | ||
http-body = "0.4.5" | ||
pin-project-lite = "0.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not really new dependencies, they are already used by tonic & tower, but I need to name the types.
I can extend this to other client methods in follow-up PRs if this gets accepted. |
e8cd55c
to
852651e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is both very cool and very nicely coded @crepererum -- thank you and well done ❤️
I had some small naming / comment suggestions, but otherwise 🚀
@@ -204,16 +204,14 @@ impl FlightClient { | |||
pub async fn do_get(&mut self, ticket: Ticket) -> Result<FlightRecordBatchStream> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other methods on this client that might be interested in server headers/trailers -- like do_exchange and do_put. Maybe we can file a ticket to track adding support for them too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a239401
to
147ff80
Compare
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
147ff80
to
74ed1df
Compare
74ed1df
to
8adf5e3
Compare
|
||
/// Extract [`LazyTrailers`] from [`Streaming`] [tonic] response. | ||
/// | ||
/// Note that [`LazyTrailers`] has inner mutability and will only hold actual data after [`ExtractTrailersStream`] is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Which issue does this PR close?
-
Rationale for this change
HTTP/2 headers can already be sent by the client (and trivially by the server as part of the
tonic::Response
object). However the the client doesn't expose the response headers yet. They can include debug information like server version or other metadata.Trailers are less commonly used but can include information that is only available AFTER the response stream finishes, e.g. "number of scanned files", "total rows read from files", etc. Tonic doesn't have a super nice way to write them from the server side, but a tower layer makes that possible. Also we have to consider non-Rust implementations that can make use of trailers.
People that read the HTTP/2 spec may wonder how headers and trailers are encoded in a stream scenario. Turns out that they have their own
HEADERS
message. The firstHEADERS
message transmit the HTTP headers, the last one at the stream end (w/ theEND_STREAM
flag set) the trailers. Now you may wonder if you could send headers mid-stream as well. Now the HTTP/2 spec doesn't seem to disallow that, but:neither tonic and tower have a way to do that
this stackoverflow answer suggests that this is not allowed because HTTP itself has no semantic for that and indeed the HTTP/2 spec say:
This is also confirmed by this stackoverflow answer.
So I think metadata can only be sent at the beginning and at the end of a stream. Everything else would also be a bit of an API mess.
What changes are included in this PR?
Wires HTTP/2 headers and trailers into flight client
DoGet
method. Tests included.Are there any user-facing changes?
New methods to get headers and trailers.