Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for trailing headers #1837

Closed
Albertoimpl opened this issue Oct 4, 2021 · 0 comments · Fixed by #1841
Closed

Support for trailing headers #1837

Albertoimpl opened this issue Oct 4, 2021 · 0 comments · Fixed by #1841
Assignees
Labels
type/enhancement A general enhancement
Milestone

Comments

@Albertoimpl
Copy link

As of today, there is no way to pass through trailing headers into any response, because of that Http2StreamFrameToHttpObjectCodec will not be able, when encoding the last content, to send the End of stream.

This is a problem when using gRPC since the protocol relies on trailing headers.

Considered alternatives

Not really an alternative but, adding a new DefaultHttp2HeadersFrame when markSentBody, will lead to the right code-path.

diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java
index f48a2276..6490447c 100644
--- a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java
+++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java
@@ -57,6 +57,8 @@ import io.netty.handler.codec.http.multipart.HttpData;
 import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
 import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
 import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus;
+import io.netty.handler.codec.http2.DefaultHttp2Headers;
+import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame;
 import io.netty.handler.codec.http2.HttpConversionUtil;
 import io.netty.util.AsciiString;
 import io.netty.util.ReferenceCountUtil;
@@ -629,7 +631,10 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
                        f = channel().writeAndFlush(newFullBodyMessage(EMPTY_BUFFER));
                }
                else if (markSentBody()) {
-                       f = channel().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
+//                     f = channel().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
+                       f = channel()
+                                       .writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers(false)
+                                                       .add("grpc-status", "0"), true));
                }
                else {
                        discard();

Additional context

https://github.com/netty/netty/blob/201f6b6bb2dcdff07df6e30552b96fedbcf21759/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2StreamFrameToHttpObjectCodec.java#L134-L137

@Albertoimpl Albertoimpl added status/need-triage A new issue that still need to be evaluated as a whole type/enhancement A general enhancement labels Oct 4, 2021
@violetagg violetagg self-assigned this Oct 4, 2021
@violetagg violetagg removed the status/need-triage A new issue that still need to be evaluated as a whole label Oct 4, 2021
@violetagg violetagg added this to the 1.0.12 milestone Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants