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/03/09 05:29:49 UTC

[dubbo] branch 3.0 updated: Remove rpc context to avoid http2 headers override (#7345)

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 2e7151e  Remove rpc context to avoid http2 headers override (#7345)
2e7151e is described below

commit 2e7151e17f1d74580bcf9ddae34040e802461015
Author: GuoHao <gu...@gmail.com>
AuthorDate: Tue Mar 9 13:29:34 2021 +0800

    Remove rpc context to avoid http2 headers override (#7345)
---
 .../org/apache/dubbo/rpc/protocol/tri/AbstractStream.java |  6 ++++++
 .../org/apache/dubbo/rpc/protocol/tri/ServerStream.java   | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
index 8782cd0..964d0cd 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/AbstractStream.java
@@ -130,6 +130,9 @@ public abstract class AbstractStream implements Stream {
         Map<String, Object> attachments = new HashMap<>();
         for (Map.Entry<CharSequence, CharSequence> header : headers) {
             String key = header.getKey().toString();
+            if(Http2Headers.PseudoHeaderName.isPseudoHeader(key)){
+                continue;
+            }
 
             if (ENABLE_ATTACHMENT_WRAP) {
                 if (key.endsWith("-tw-bin") && key.length() > 7) {
@@ -156,6 +159,9 @@ public abstract class AbstractStream implements Stream {
     protected void convertAttachment(Http2Headers trailers, Map<String, Object> attachments) throws IOException {
         for (Map.Entry<String, Object> entry : attachments.entrySet()) {
             final String key = entry.getKey().toLowerCase(Locale.ROOT);
+            if(Http2Headers.PseudoHeaderName.isPseudoHeader(key)){
+                continue;
+            }
             final Object v = entry.getValue();
             if (!ENABLE_ATTACHMENT_WRAP) {
                 if (v instanceof String) {
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStream.java
index bd0bf8c..a001364 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStream.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ServerStream.java
@@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.AppResponse;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.RpcInvocation;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 import org.apache.dubbo.rpc.model.MethodDescriptor;
@@ -183,12 +184,12 @@ public class ServerStream extends AbstractStream implements Stream {
                     ClassLoadUtil.switchContextLoader(tccl);
                 }
 
-                final Http2Headers trailers = new DefaultHttp2Headers()
-                        .setInt(TripleConstant.STATUS_KEY, GrpcStatus.Code.OK.code);
+                final Http2Headers trailers = new DefaultHttp2Headers();
                 final Map<String, Object> attachments = response.getObjectAttachments();
                 if (attachments != null) {
                     convertAttachment(trailers, attachments);
                 }
+                trailers.setInt(TripleConstant.STATUS_KEY, GrpcStatus.Code.OK.code);
                 ctx.write(new DefaultHttp2HeadersFrame(http2Headers));
                 final DefaultHttp2DataFrame data = new DefaultHttp2DataFrame(buf);
                 ctx.write(data);
@@ -206,6 +207,7 @@ public class ServerStream extends AbstractStream implements Stream {
         };
 
         future.whenComplete(onComplete);
+        RpcContext.removeContext();
     }
 
 
@@ -277,6 +279,15 @@ public class ServerStream extends AbstractStream implements Stream {
         inv.setParameterTypes(methodDescriptor.getParameterClasses());
         inv.setReturnTypes(methodDescriptor.getReturnTypes());
         final Map<String, Object> attachments = parseHeadersToMap(getHeaders());
+        attachments.remove("content-type");
+        attachments.remove("interface");
+        attachments.remove("tri-service-version");
+        attachments.remove("tri-service-group");
+        attachments.remove("serialization");
+        attachments.remove("te");
+        attachments.remove("path");
+        attachments.remove("grpc-status");
+        attachments.remove("grpc-message");
         inv.setObjectAttachments(attachments);
         return inv;
     }