Skip to content
Snippets Groups Projects
Commit 2565e732 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

merging of trailers on server-side

parent e64825c3
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ namespace Grpc.Core.Internal ...@@ -76,7 +76,7 @@ namespace Grpc.Core.Internal
{ {
Logger.Warning(e, "Exception occured in handler."); Logger.Warning(e, "Exception occured in handler.");
} }
status = HandlerUtils.StatusFromException(e); status = HandlerUtils.StatusFromException(e, context.ResponseTrailers);
} }
try try
{ {
...@@ -133,7 +133,7 @@ namespace Grpc.Core.Internal ...@@ -133,7 +133,7 @@ namespace Grpc.Core.Internal
{ {
Logger.Warning(e, "Exception occured in handler."); Logger.Warning(e, "Exception occured in handler.");
} }
status = HandlerUtils.StatusFromException(e); status = HandlerUtils.StatusFromException(e, context.ResponseTrailers);
} }
try try
...@@ -191,7 +191,7 @@ namespace Grpc.Core.Internal ...@@ -191,7 +191,7 @@ namespace Grpc.Core.Internal
{ {
Logger.Warning(e, "Exception occured in handler."); Logger.Warning(e, "Exception occured in handler.");
} }
status = HandlerUtils.StatusFromException(e); status = HandlerUtils.StatusFromException(e, context.ResponseTrailers);
} }
try try
...@@ -247,7 +247,7 @@ namespace Grpc.Core.Internal ...@@ -247,7 +247,7 @@ namespace Grpc.Core.Internal
{ {
Logger.Warning(e, "Exception occured in handler."); Logger.Warning(e, "Exception occured in handler.");
} }
status = HandlerUtils.StatusFromException(e); status = HandlerUtils.StatusFromException(e, context.ResponseTrailers);
} }
try try
{ {
...@@ -292,11 +292,20 @@ namespace Grpc.Core.Internal ...@@ -292,11 +292,20 @@ namespace Grpc.Core.Internal
internal static class HandlerUtils internal static class HandlerUtils
{ {
public static Status StatusFromException(Exception e) public static Status StatusFromException(Exception e, Metadata callContextResponseTrailers)
{ {
var rpcException = e as RpcException; var rpcException = e as RpcException;
if (rpcException != null) if (rpcException != null)
{ {
// There are two sources of metadata entries on the server-side:
// 1. serverCallContext.ResponseTrailers
// 2. trailers in RpcException thrown by user code in server side handler.
// As metadata allows duplicate keys, the logical thing to do is
// to just merge trailers from RpcException into serverCallContext.ResponseTrailers.
foreach (var entry in rpcException.Trailers)
{
callContextResponseTrailers.Add(entry);
}
// use the status thrown by handler. // use the status thrown by handler.
return rpcException.Status; return rpcException.Status;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment