You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "lizhimins (via GitHub)" <gi...@apache.org> on 2023/06/29 08:56:11 UTC
[GitHub] [rocketmq] lizhimins commented on a diff in pull request #6958: [ISSUE #6957] Support Proxy Protocol for gRPC and Remoting server
lizhimins commented on code in PR #6958:
URL: https://github.com/apache/rocketmq/pull/6958#discussion_r1246336265
##########
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:
use put if not exist to cache value
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org