You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/05/21 11:52:36 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #7224: ARROW-8858: [FlightRPC] ensure binary/multi-valued headers are properly exposed

pitrou commented on a change in pull request #7224:
URL: https://github.com/apache/arrow/pull/7224#discussion_r428602803



##########
File path: python/pyarrow/_flight.pyx
##########
@@ -1785,15 +1786,16 @@ cdef dict convert_headers(const CCallHeaders& c_headers):
         CCallHeaders.const_iterator header_iter = c_headers.cbegin()
     headers = {}
     while header_iter != c_headers.cend():
-        # Headers in gRPC (and HTTP/1, HTTP/2) are required to be
-        # valid ASCII.
         header = c_string(deref(header_iter).first).decode("ascii")
+        if header not in headers:
+            headers[header] = []
+        value = c_string(deref(header_iter).second)
         if not header.endswith("-bin"):
-            # Ignore -bin (gRPC binary) headers
-            value = c_string(deref(header_iter).second).decode("ascii")
-            if header not in headers:
-                headers[header] = []
-            headers[header].append(value)
+            # Text header values in gRPC (and HTTP/1, HTTP/2) are
+            # required to be valid ASCII. Binary header values are
+            # exposed as bytes.
+            value = value.decode("ascii")
+        headers[header].append(value)

Review comment:
       `headers.setdefault(header, []).append(value)` automatically creates the empty list entry for you.

##########
File path: python/pyarrow/tests/test_flight.py
##########
@@ -483,6 +495,51 @@ def sending_headers(self):
         }
 
 
+class MultiHeaderClientMiddlewareFactory(ClientMiddlewareFactory):
+    """Test sending/receiving multiple (binary-valued) headers."""
+
+    def __init__(self):
+        self.last_headers = {}

Review comment:
       This isn't ever used, right?

##########
File path: python/pyarrow/tests/test_flight.py
##########
@@ -452,6 +453,17 @@ def do_action(self, context, action):
         return iter([flight.Result(b"")])
 
 
+class MultiHeaderFlightServer(FlightServerBase):
+    """Test sending/receiving multiple (binary-valued) headers."""
+
+    def do_action(self, context, action):
+        middleware = context.get_middleware("test")
+        if middleware:

Review comment:
       Is this condition useful?

##########
File path: python/pyarrow/tests/test_flight.py
##########
@@ -452,6 +453,17 @@ def do_action(self, context, action):
         return iter([flight.Result(b"")])
 
 
+class MultiHeaderFlightServer(FlightServerBase):
+    """Test sending/receiving multiple (binary-valued) headers."""
+
+    def do_action(self, context, action):
+        middleware = context.get_middleware("test")
+        if middleware:
+            headers = repr(middleware.client_headers).encode("utf-8")
+            return iter([flight.Result(headers)])

Review comment:
       Is `iter` required?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org