예제 #1
0
        public static HttpRequest Create(System.Web.HttpRequestBase httpRequest)
        {
            if (httpRequest == null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            HttpRequest result = new HttpRequest(new HttpRequest.CreateOptions
            {
                Url           = httpRequest.Url,
                HttpMethod    = httpRequest.HttpMethod,
                UserAgent     = httpRequest.UserAgent,
                HttpReferer   = httpRequest.UrlReferrer?.ToString(),
                RemoteAddress = httpRequest.UserHostAddress,
                MachineName   = InternalHelpers.GetMachineName(httpRequest)
            });

            RequestProperties.CreateOptions propertiesOptions = new RequestProperties.CreateOptions();

            propertiesOptions.ServerVariables = InternalHelpers.ToKeyValuePair(httpRequest.ServerVariables);

            if (httpRequest.Unvalidated != null)
            {
                propertiesOptions.Headers     = InternalHelpers.ToKeyValuePair(httpRequest.Unvalidated.Headers);
                propertiesOptions.Cookies     = InternalHelpers.ToKeyValuePair(httpRequest.Unvalidated.Cookies);
                propertiesOptions.QueryString = InternalHelpers.ToKeyValuePair(httpRequest.Unvalidated.QueryString);

                if (KissLogConfiguration.Options.Handlers.ShouldLogFormData.Invoke(result) == true)
                {
                    propertiesOptions.FormData = InternalHelpers.ToKeyValuePair(httpRequest.Unvalidated.Form);
                }
            }

            if (KissLog.InternalHelpers.CanReadRequestInputStream(propertiesOptions.Headers))
            {
                if (KissLogConfiguration.Options.Handlers.ShouldLogInputStream.Invoke(result) == true)
                {
                    propertiesOptions.InputStream = KissLog.InternalHelpers.WrapInTryCatch(() =>
                    {
                        return(InternalHelpers.ReadInputStream(httpRequest));
                    });
                }
            }

            result.SetProperties(new RequestProperties(propertiesOptions));

            return(result);
        }
예제 #2
0
        internal void OnPostAuthenticateRquest(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            var    factory = new LoggerFactory();
            Logger logger  = factory.GetInstance(httpContext);

            if (logger.DataContainer.HttpProperties == null && httpContext.Request != null)
            {
                KissLog.Http.HttpRequest httpRequest = HttpRequestFactory.Create(httpContext.Request);
                logger.DataContainer.SetHttpProperties(new Http.HttpProperties(httpRequest));
            }

            if (logger.DataContainer.HttpProperties == null)
            {
                return;
            }

            bool isAuthenticated = httpContext.User?.Identity?.IsAuthenticated ?? false;

            logger.DataContainer.HttpProperties.Request.SetIsAuthenticated(isAuthenticated);

            if (httpContext.User == null || httpContext.User is ClaimsPrincipal == false)
            {
                return;
            }

            ClaimsPrincipal claimsPrincipal = httpContext.User as ClaimsPrincipal;

            if (claimsPrincipal.Identity == null || claimsPrincipal.Identity is ClaimsIdentity == false)
            {
                return;
            }

            ClaimsIdentity claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity;

            List <KeyValuePair <string, string> > claims = InternalHelpers.ToKeyValuePair(claimsIdentity);

            logger.DataContainer.HttpProperties.Request.Properties.SetClaims(claims);
        }
예제 #3
0
        public static HttpResponse Create(System.Web.HttpResponseBase httpResponse, long contentLength)
        {
            if (httpResponse == null)
            {
                throw new ArgumentNullException(nameof(httpResponse));
            }

            if (contentLength < 0)
            {
                throw new ArgumentException(nameof(contentLength));
            }

            var options = new HttpResponse.CreateOptions();

            options.StatusCode = httpResponse.StatusCode;
            options.Properties = new ResponseProperties(new ResponseProperties.CreateOptions
            {
                Headers       = InternalHelpers.ToKeyValuePair(httpResponse.Headers),
                ContentLength = contentLength
            });

            return(new HttpResponse(options));
        }