Exemplo n.º 1
0
        /// <summary>
        /// Invokes the middleware.
        /// </summary>
        public async Task Invoke(HttpContext httpContext)
        {
            var httpRequestMessage = FacilityAspNetCoreUtility.CreateHttpRequestMessage(httpContext.Request);

            HttpResponseMessage httpResponseMessage;

            try
            {
                httpResponseMessage = await m_handler.TryHandleHttpRequestAsync(httpRequestMessage, httpContext.RequestAborted).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                httpResponseMessage = FacilityAspNetCoreUtility.CreateHttpResponseMessage(exception);
            }

            if (httpResponseMessage != null)
            {
                using (httpResponseMessage)
                    await FacilityAspNetCoreUtility.WriteHttpResponseMessageAsync(httpResponseMessage, httpContext.Response);
            }
            else
            {
                await m_next(httpContext).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     if (context.ActionArguments.ContainsKey(c_httpRequestKey) &&
         context.ActionArguments[c_httpRequestKey].GetType() == typeof(HttpRequestMessage))
     {
         context.ActionArguments[c_httpRequestKey] = FacilityAspNetCoreUtility.CreateHttpRequestMessage(context.HttpContext.Request);
     }
 }