kylepbit commented on a change in pull request #8724:
URL: https://github.com/apache/arrow/pull/8724#discussion_r527968893



##########
File path: cpp/src/arrow/flight/client_header_auth_middleware.cc
##########
@@ -0,0 +1,124 @@
+// 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.
+
+// Interfaces for defining middleware for Flight clients. Currently
+// experimental.
+
+#include "client_header_auth_middleware.h"
+#include "client_middleware.h"
+#include "client_auth.h"
+#include "client.h"
+
+namespace arrow {
+namespace flight {
+
+  std::string base64_encode(const std::string& input);
+
+  ClientBearerTokenMiddleware::ClientBearerTokenMiddleware(
+    std::pair<std::string, std::string>* bearer_token_)
+        : bearer_token(bearer_token_) { }
+
+  void ClientBearerTokenMiddleware::SendingHeaders(AddCallHeaders* 
outgoing_headers) { }
+
+  void ClientBearerTokenMiddleware::ReceivedHeaders(
+    const CallHeaders& incoming_headers) {
+    // Grab the auth token if one exists.
+    auto bearer_iter = incoming_headers.find(AUTH_HEADER);
+    if (bearer_iter == incoming_headers.end()) {
+      return;
+    }
+
+    // Check if the value of the auth token starts with the bearer prefix, 
latch the token.
+    std::string bearer_val = bearer_iter->second.to_string();
+    if (bearer_val.size() > BEARER_PREFIX.size()) {
+      bool hasPrefix = std::equal(bearer_val.begin(), bearer_val.begin() + 
BEARER_PREFIX.size(), BEARER_PREFIX.begin(),
+        [] (const char& char1, const char& char2) {
+          return (std::toupper(char1) == std::toupper(char2));
+        }
+      );
+      if (hasPrefix) {
+        *bearer_token = std::make_pair(AUTH_HEADER, bearer_val);
+      }
+    }
+  }
+
+  void ClientBearerTokenMiddleware::CallCompleted(const Status& status) { }
+
+  void ClientBearerTokenFactory::StartCall(const CallInfo& info, 
std::unique_ptr<ClientMiddleware>* middleware) {

Review comment:
       Would it be better to pass a reference instead of a pointer?




----------------------------------------------------------------
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:
[email protected]


Reply via email to