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/11/06 01:29:26 UTC

[GitHub] [arrow] lidavidm commented on a change in pull request #8572: ARROW-10467: [FlightRPC][Java] Add the ability to pass arbitrary client headers.

lidavidm commented on a change in pull request #8572:
URL: https://github.com/apache/arrow/pull/8572#discussion_r518470154



##########
File path: java/flight/flight-core/src/main/java/org/apache/arrow/flight/HeaderCallOption.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.flight;
+
+import io.grpc.Metadata;
+import io.grpc.stub.AbstractStub;
+import io.grpc.stub.MetadataUtils;
+
+/**
+ * Method option for supplying headers to method calls.
+ */
+public class HeaderCallOption implements CallOptions.GrpcCallOption {
+  private final Metadata propertiesMetadata = new Metadata();
+
+  /**
+   * Header property constructor.
+   *
+   * @param headers the headers that should be sent across. If a header is a string, it should only be valid ASCII
+   *                characters. Binary headers should end in "-bin".
+   */
+  public HeaderCallOption(CallHeaders headers) {
+    for (String key : headers.keys()) {
+      if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
+        propertiesMetadata.put(

Review comment:
       This discards secondary values of multi-valued headers.

##########
File path: java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightCallHeaders.java
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.flight;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+
+import io.grpc.Metadata;
+
+/**
+ * An implementation of the Flight headers interface for headers.
+ */
+public class FlightCallHeaders implements CallHeaders {
+  private final Multimap<String, Object> keysAndValues;
+
+  public FlightCallHeaders() {
+    this.keysAndValues = ArrayListMultimap.create();
+  }
+
+  @Override
+  public String get(String key) {
+    if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
+      return new String((byte[]) Iterables.get(this.keysAndValues.get(key), 0));
+    }
+
+    return (String) Iterables.get(this.keysAndValues.get(key), 0);

Review comment:
       Iterables.get appears to throw if there's no element; for consistency with MetadataAdapter this should return null when there's no element.




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