/// <summary>
        ///
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        public Task Invoke(IDictionary <string, object> environment)
        {
            // Check if the URL matches any expected paths
            var context = new StaticFileContext(environment, _options, _matchUrl);

            if (context.ValidateMethod() &&
                context.ValidatePath() &&
                context.LookupContentType() &&
                context.LookupFileInfo())
            {
                context.ComprehendRequestHeaders();
                context.ApplyResponseHeaders();

                StaticFileContext.PreconditionState preconditionState = context.GetPreconditionState();
                if (preconditionState == StaticFileContext.PreconditionState.NotModified)
                {
                    return(context.SendStatusAsync(Constants.Status304NotModified));
                }
                if (preconditionState == StaticFileContext.PreconditionState.PreconditionFailed)
                {
                    return(context.SendStatusAsync(Constants.Status412PreconditionFailed));
                }
                if (context.IsHeadMethod)
                {
                    return(context.SendStatusAsync(Constants.Status200Ok));
                }
                return(context.SendAsync(Constants.Status200Ok));
            }

            return(_next(environment));
        }
示例#2
0
        /// <summary>
        /// Processes a request to determine if it matches a known file, and if so, serves it.
        /// </summary>
        /// <param name="environment">OWIN environment dictionary which stores state information about the request, response and relevant server state.</param>
        /// <returns></returns>
        public Task Invoke(IDictionary <string, object> environment)
        {
            IOwinContext context = new OwinContext(environment);
            //Console.WriteLine("[LOG.REQUEST] -> " + context.Request.Uri.ToString());


            var fileContext = new StaticFileContext(context, _options, _matchUrl);

            if (fileContext.ValidateMethod() &&
                fileContext.ValidatePath() &&
                fileContext.LookupContentType() &&
                fileContext.LookupFileInfo())
            {
                fileContext.ComprehendRequestHeaders();

                switch (fileContext.GetPreconditionState())
                {
                case StaticFileContext.PreconditionState.Unspecified:
                case StaticFileContext.PreconditionState.ShouldProcess:
                    if (fileContext.IsHeadMethod)
                    {
                        return(fileContext.SendStatusAsync(Constants.Status200Ok));
                    }
                    if (fileContext.IsRangeRequest)
                    {
                        return(fileContext.SendRangeAsync());
                    }
                    return(fileContext.SendAsync());

                case StaticFileContext.PreconditionState.NotModified:
                    return(fileContext.SendStatusAsync(Constants.Status304NotModified));

                case StaticFileContext.PreconditionState.PreconditionFailed:
                    return(fileContext.SendStatusAsync(Constants.Status412PreconditionFailed));

                default:
                    throw new NotImplementedException(fileContext.GetPreconditionState().ToString());
                }
            }

            return(_next(environment));
        }
        /// <summary>
        /// Processes a request to determine if it matches a known file, and if so, serves it.
        /// </summary>
        /// <param name="environment">OWIN environment dictionary which stores state information about the request, response and relevant server state.</param>
        /// <returns></returns>
        public Task Invoke(IDictionary<string, object> environment)
        {
            IOwinContext context = new OwinContext(environment);

            var fileContext = new StaticFileContext(context, _options, _matchUrl);
            if (fileContext.ValidateMethod()
                && fileContext.ValidatePath()
                && fileContext.LookupContentType()
                && fileContext.LookupFileInfo())
            {
                fileContext.ComprehendRequestHeaders();

                switch (fileContext.GetPreconditionState())
                {
                    case StaticFileContext.PreconditionState.Unspecified:
                    case StaticFileContext.PreconditionState.ShouldProcess:
                        if (fileContext.IsHeadMethod)
                        {
                            return fileContext.SendStatusAsync(Constants.Status200Ok);
                        }
                        if (fileContext.IsRangeRequest)
                        {
                            return fileContext.SendRangeAsync();
                        }
                        return fileContext.SendAsync();

                    case StaticFileContext.PreconditionState.NotModified:
                        return fileContext.SendStatusAsync(Constants.Status304NotModified);

                    case StaticFileContext.PreconditionState.PreconditionFailed:
                        return fileContext.SendStatusAsync(Constants.Status412PreconditionFailed);

                    default:
                        throw new NotImplementedException(fileContext.GetPreconditionState().ToString());
                }
            }

            return _next(environment);
        }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        public Task Invoke(IDictionary<string, object> environment)
        {
            // Check if the URL matches any expected paths
            var context = new StaticFileContext(environment, _options, _matchUrl);
            if (context.ValidateMethod()
                && context.ValidatePath()
                && context.LookupContentType()
                && context.LookupFileInfo())
            {
                context.ComprehendRequestHeaders();
                context.ApplyResponseHeaders();

                StaticFileContext.PreconditionState preconditionState = context.GetPreconditionState();
                if (preconditionState == StaticFileContext.PreconditionState.NotModified)
                {
                    return context.SendStatusAsync(Constants.Status304NotModified);
                }
                if (preconditionState == StaticFileContext.PreconditionState.PreconditionFailed)
                {
                    return context.SendStatusAsync(Constants.Status412PreconditionFailed);
                }
                if (context.IsHeadMethod)
                {
                    return context.SendStatusAsync(Constants.Status200Ok);
                }
                return context.SendAsync(Constants.Status200Ok);
            }

            return _next(environment);
        }