lizhimins commented on code in PR #6958:
URL: https://github.com/apache/rocketmq/pull/6958#discussion_r1246337922


##########
proxy/src/main/java/org/apache/rocketmq/proxy/grpc/interceptor/HeaderInterceptor.java:
##########
@@ -55,4 +74,13 @@ private String parseSocketAddress(SocketAddress 
socketAddress) {
 
         return "";
     }
+
+    private String getProxyProtocolAddress(Attributes attributes) {
+        String proxyProtocolAddr = 
attributes.get(AttributesConstants.PROXY_PROTOCOL_ADDR);
+        String proxyProtocolPort = 
attributes.get(AttributesConstants.PROXY_PROTOCOL_PORT);
+        if (StringUtils.isBlank(proxyProtocolAddr) || 
StringUtils.isEmpty(proxyProtocolPort)) {

Review Comment:
   use isBlank?



##########
proxy/src/main/java/org/apache/rocketmq/proxy/grpc/interceptor/HeaderInterceptor.java:
##########
@@ -33,13 +38,27 @@ public <R, W> ServerCall.Listener<R> interceptCall(
         Metadata headers,
         ServerCallHandler<R, W> next
     ) {
-        SocketAddress remoteSocketAddress = 
call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
-        String remoteAddress = parseSocketAddress(remoteSocketAddress);
+        String remoteAddress = getProxyProtocolAddress(call.getAttributes());
+        if (StringUtils.isBlank(remoteAddress)) {
+            SocketAddress remoteSocketAddress = 
call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
+            remoteAddress = parseSocketAddress(remoteSocketAddress);
+        }
         headers.put(InterceptorConstants.REMOTE_ADDRESS, remoteAddress);
 
         SocketAddress localSocketAddress = 
call.getAttributes().get(Grpc.TRANSPORT_ATTR_LOCAL_ADDR);
         String localAddress = parseSocketAddress(localSocketAddress);
         headers.put(InterceptorConstants.LOCAL_ADDRESS, localAddress);
+
+        for (Attributes.Key<?> key : call.getAttributes().keys()) {
+            if (!StringUtils.startsWith(key.toString(), 
HAProxyConstants.PROXY_PROTOCOL_PREFIX)) {
+                continue;
+            }
+            Metadata.Key<String> headerKey
+                    = Metadata.Key.of(key.toString(), 
Metadata.ASCII_STRING_MARSHALLER);
+            String headerValue = String.valueOf(call.getAttributes().get(key));
+            headers.put(headerKey, headerValue);

Review Comment:
   In http protocol, new header will append headers rather than put to map



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