You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by gu...@apache.org on 2021/08/17 07:48:15 UTC
[dubbo] branch 3.0 updated: Fixed TLS using scheme HTTP when using
TRI protocol (#8497)
This is an automated email from the ASF dual-hosted git repository.
guohao pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new c3c6f71 Fixed TLS using scheme HTTP when using TRI protocol (#8497)
c3c6f71 is described below
commit c3c6f7176fdb8ab3df0ff72755a5ebc86bb734cd
Author: earthchen <yo...@duobei.com>
AuthorDate: Tue Aug 17 02:47:59 2021 -0500
Fixed TLS using scheme HTTP when using TRI protocol (#8497)
* Fixed TLS using scheme HTTP when using TRI protocol
* change ssl config to channel attr
* Reuse scheme variable & Set attr only if ssl enabled
---
.../rpc/protocol/tri/ClientTransportObserver.java | 8 +++++++-
.../dubbo/rpc/protocol/tri/TripleClientHandler.java | 19 ++++++++++++-------
.../apache/dubbo/rpc/protocol/tri/TripleConstant.java | 11 ++++++++++-
3 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ClientTransportObserver.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ClientTransportObserver.java
index cc68861..871e874 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ClientTransportObserver.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ClientTransportObserver.java
@@ -30,7 +30,7 @@ import io.netty.handler.codec.http2.Http2StreamChannelBootstrap;
import io.netty.util.AsciiString;
public class ClientTransportObserver implements TransportObserver {
- private static final AsciiString SCHEME = AsciiString.of("http");
+ private final AsciiString SCHEME;
private final ChannelHandlerContext ctx;
private final Http2StreamChannel streamChannel;
private final ChannelPromise promise;
@@ -41,6 +41,12 @@ public class ClientTransportObserver implements TransportObserver {
public ClientTransportObserver(ChannelHandlerContext ctx, AbstractClientStream stream, ChannelPromise promise) {
this.ctx = ctx;
this.promise = promise;
+ Boolean ssl = ctx.channel().attr(TripleConstant.SSL_ATTRIBUTE_KEY).get();
+ if (ssl != null && ssl) {
+ SCHEME = TripleConstant.HTTPS_SCHEME;
+ } else {
+ SCHEME = TripleConstant.HTTP_SCHEME;
+ }
final Http2StreamChannelBootstrap streamChannelBootstrap = new Http2StreamChannelBootstrap(ctx.channel());
streamChannel = streamChannelBootstrap.open().syncUninterruptibly().getNow();
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleClientHandler.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleClientHandler.java
index f70d414..3600143 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleClientHandler.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleClientHandler.java
@@ -16,8 +16,16 @@
*/
package org.apache.dubbo.rpc.protocol.tri;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import io.netty.handler.codec.http2.Http2GoAwayFrame;
+import io.netty.handler.codec.http2.Http2SettingsFrame;
+import io.netty.util.ReferenceCountUtil;
import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.stream.StreamObserver;
+import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.remoting.api.Connection;
import org.apache.dubbo.remoting.api.ConnectionHandler;
@@ -31,13 +39,6 @@ import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ServiceRepository;
-import io.netty.channel.ChannelDuplexHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPromise;
-import io.netty.handler.codec.http2.Http2GoAwayFrame;
-import io.netty.handler.codec.http2.Http2SettingsFrame;
-import io.netty.util.ReferenceCountUtil;
-
public class TripleClientHandler extends ChannelDuplexHandler {
@Override
@@ -82,6 +83,10 @@ public class TripleClientHandler extends ChannelDuplexHandler {
} else {
stream = AbstractClientStream.stream(url);
}
+ String ssl = url.getParameter(CommonConstants.SSL_ENABLED_KEY);
+ if (StringUtils.isNotEmpty(ssl)) {
+ ctx.channel().attr(TripleConstant.SSL_ATTRIBUTE_KEY).set(Boolean.parseBoolean(ssl));
+ }
stream.service(service)
.connection(Connection.getConnectionFromChannel(ctx.channel()))
.method(methodDescriptor)
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleConstant.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleConstant.java
index a18b351..7943012 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleConstant.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleConstant.java
@@ -17,6 +17,9 @@
package org.apache.dubbo.rpc.protocol.tri;
import io.netty.handler.codec.http2.Http2CodecUtil;
+import io.netty.util.AsciiString;
+import io.netty.util.AttributeKey;
+import org.apache.dubbo.common.constants.CommonConstants;
public interface TripleConstant {
String CONTENT_PROTO = "application/grpc+proto";
@@ -24,8 +27,14 @@ public interface TripleConstant {
String TRI_VERSION = "1.0.0";
String SERIALIZATION_KEY = "serialization";
- String TE_KEY="te";
+ String TE_KEY = "te";
// each header size
long DEFAULT_HEADER_LIST_SIZE = Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE;
+ AttributeKey<Boolean> SSL_ATTRIBUTE_KEY = AttributeKey.valueOf(CommonConstants.SSL_ENABLED_KEY);
+
+
+ AsciiString HTTPS_SCHEME = AsciiString.of("https");
+ AsciiString HTTP_SCHEME = AsciiString.of("http");
+
}