public RequestDelegate CreateUnimplementedMethod()
        {
            var logger = _loggerFactory.CreateLogger <ServerCallHandlerFactory <TService> >();

            return(httpContext =>
            {
                GrpcProtocolHelpers.AddProtocolHeaders(httpContext.Response);

                var unimplementedMethod = httpContext.Request.RouteValues["unimplementedMethod"]?.ToString() ?? "<unknown>";
                Log.MethodUnimplemented(logger, unimplementedMethod);

                GrpcProtocolHelpers.SetStatus(GrpcProtocolHelpers.GetTrailersDestination(httpContext.Response), new Status(StatusCode.Unimplemented, "Method is unimplemented."));
                return Task.CompletedTask;
            });
        }
        public static void ConsolidateTrailers(this HttpResponse httpResponse, HttpContextServerCallContext context)
        {
            var trailersDestination = GrpcProtocolHelpers.GetTrailersDestination(httpResponse);

            if (context.HasResponseTrailers)
            {
                foreach (var trailer in context.ResponseTrailers)
                {
                    var value = (trailer.IsBinary) ? Convert.ToBase64String(trailer.ValueBytes) : trailer.Value;
                    trailersDestination.Append(trailer.Key, value);
                }
            }

            // Append status trailers, these overwrite any existing status trailers set via ServerCallContext.ResponseTrailers
            GrpcProtocolHelpers.SetStatus(trailersDestination, context.Status);
        }
        public RequestDelegate CreateUnimplementedMethod()
        {
            var logger = _loggerFactory.CreateLogger <ServerCallHandlerFactory <TService> >();

            return(httpContext =>
            {
                // CORS preflight request should be handled by CORS middleware.
                // If it isn't then return 404 from endpoint request delegate.
                if (GrpcProtocolHelpers.IsCorsPreflightRequest(httpContext))
                {
                    httpContext.Response.StatusCode = StatusCodes.Status404NotFound;
                    return Task.CompletedTask;
                }

                GrpcProtocolHelpers.AddProtocolHeaders(httpContext.Response);

                var unimplementedMethod = httpContext.Request.RouteValues["unimplementedMethod"]?.ToString() ?? "<unknown>";
                Log.MethodUnimplemented(logger, unimplementedMethod);
                GrpcEventSource.Log.CallUnimplemented(httpContext.Request.Path.Value);

                GrpcProtocolHelpers.SetStatus(GrpcProtocolHelpers.GetTrailersDestination(httpContext.Response), new Status(StatusCode.Unimplemented, "Method is unimplemented."));
                return Task.CompletedTask;
            });
        }