alamb commented on code in PR #4727:
URL: https://github.com/apache/arrow-rs/pull/4727#discussion_r1303407710


##########
arrow-flight/src/decode.rs:
##########
@@ -98,9 +109,36 @@ impl FlightRecordBatchStream {
     {
         Self {
             inner: FlightDataDecoder::new(inner),
+            headers: MetadataMap::default(),
+            trailers: None,
+        }
+    }
+
+    /// Record response headers.
+    pub fn with_headers(self, headers: MetadataMap) -> Self {
+        Self { headers, ..self }
+    }
+
+    /// Record response trailers.
+    pub fn with_trailers(self, trailers: LazyTrailers) -> Self {
+        Self {
+            trailers: Some(trailers),
+            ..self
         }
     }
 
+    /// Headers attached to this stream.
+    pub fn headers(&self) -> &MetadataMap {
+        &self.headers
+    }
+
+    /// Trailers attached to this stream.
+    ///
+    /// This is only filled when the entire stream was consumed.

Review Comment:
   ```suggestion
       /// Note that this will return `None` until the entire stream is 
consumed. 
       /// Only after calling `next()` returns `None`, might any available 
trailers be returned. 
   ```



##########
arrow-flight/src/client.rs:
##########
@@ -204,16 +204,14 @@ impl FlightClient {
     pub async fn do_get(&mut self, ticket: Ticket) -> 
Result<FlightRecordBatchStream> {

Review Comment:
   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



##########
arrow-flight/tests/client.rs:
##########
@@ -158,18 +159,39 @@ async fn test_do_get() {
 
         let response = vec![Ok(batch.clone())];
         test_server.set_do_get_response(response);
-        let response_stream = client
+        let mut response_stream = client
             .do_get(ticket.clone())
             .await
             .expect("error making request");
 
+        assert_eq!(
+            response_stream
+                .headers()
+                .get("test-resp-header")
+                .expect("header exists")
+                .to_str()
+                .unwrap(),
+            "some_val",
+        );
+
         let expected_response = vec![batch];
-        let response: Vec<_> = response_stream
+        let response: Vec<_> = (&mut response_stream)

Review Comment:
   I think it would be good to assert that `response_stream.trailers()` returns 
`None` prior to stream exhaustion



##########
arrow-flight/src/trailers.rs:
##########
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::{
+    pin::Pin,
+    sync::{Arc, Mutex},
+    task::{Context, Poll},
+};
+
+use futures::{ready, FutureExt, Stream, StreamExt};
+use tonic::{metadata::MetadataMap, Status, Streaming};
+
+/// Extract trailers from [`Streaming`] [tonic] response.

Review Comment:
   I think expanding on the fact that returns something with inner mutability 
that is updated when the stream is exhausted (as opposed to `extract_headers` 
which returns a value immediately) would help
   
   Maybe we could call it `extract_lazy_trailers` to call attention to the fact 
it behaves differently to extract_headers



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to