Example #1
0
        public static async Task EndHttpHandlerRequestAsync(this IResponse httpRes, bool skipHeaders = false, bool skipClose = false, Func <IResponse, Task> afterHeaders = null)
        {
            if (!skipHeaders)
            {
                httpRes.ApplyGlobalResponseHeaders();
            }

            if (afterHeaders != null)
            {
                try
                {
                    await afterHeaders(httpRes).ConfigAwait();
                }
                catch (Exception e)
                {
                    var log = LogManager.LogFactory.GetLogger(typeof(HttpExtensions));
                    log.Error("Error executing async afterHeaders: " + e.Message, e);
                }
            }

            var req = httpRes.Request;

            if (req != null && !req.Items.ContainsKey(Keywords.HasLogged))
            {
                HostContext.TryResolve <IRequestLogger>()?.Log(req, req.Dto, httpRes.Dto, TimeSpan.Zero);
            }

            if (!skipClose && !httpRes.IsClosed)
            {
                await httpRes.CloseAsync().ConfigAwait();
            }

            HostContext.CompleteRequest(req);
        }
Example #2
0
        public static async Task EndHttpHandlerRequestAsync(this IResponse httpRes, bool skipHeaders = false, bool skipClose = false, Func <IResponse, Task> afterHeaders = null)
        {
            if (!skipHeaders)
            {
                httpRes.ApplyGlobalResponseHeaders();
            }

            if (afterHeaders != null)
            {
                await afterHeaders(httpRes);
            }

            var req = httpRes.Request;

            if (req != null && !req.Items.ContainsKey(Keywords.HasLogged))
            {
                HostContext.TryResolve <IRequestLogger>()?.Log(req, req.Dto, httpRes.Dto, TimeSpan.Zero);
            }

            if (!skipClose && !httpRes.IsClosed)
            {
                await httpRes.CloseAsync();
            }

            HostContext.CompleteRequest(req);
        }