private async Task HandleServerTimingAsTrailerHeaderAsync(HttpContext context, IServerTiming serverTiming)
        {
            context.Response.DeclareTrailer(HeaderNames.ServerTiming);

            serverTiming.SetServerTimingDeliveryMode(ServerTimingDeliveryMode.Trailer);

            await _next(context);

            context.Response.SetServerTimingTrailer(new ServerTimingHeaderValue(serverTiming.Metrics));
        }
        private Task HandleServerTimingAsResponseHeaderAsync(HttpContext context, IServerTiming serverTiming)
        {
            context.Response.OnStarting(() => {
                if (serverTiming.Metrics.Count > 0)
                {
                    context.Response.SetServerTiming(new ServerTimingHeaderValue(serverTiming.Metrics));
                }

                return(_completedTask);
            });

            serverTiming.SetServerTimingDeliveryMode(ServerTimingDeliveryMode.ResponseHeader);

            return(_next(context));
        }