コード例 #1
0
ファイル: StaticMiddleware.cs プロジェクト: c4net/OWIN-Static
        protected override StaticResponse GetResponse(Location location)
        {
            if (!TestFilters(location))
                return null;

            var info = GetLocalFileInfo(location.Path, sources, indexFiles, allowHidden);
            if (info == null)
                return null;

            if (info is DirectoryInfo)
                return redirectIfFolder ? StaticResponse.Redirect(GetFolderRedirectLocation(location)) : null;

            var result = new StaticResponse(info.FullName.GetContentType(), GetFileStream(info.FullName));
            if (expires != DateTimeOffset.MinValue)
                result.Headers.Expires.Value = expires;
            if (maxAge != 0)
                result.Headers.CacheControl.MaxAge = maxAge;
            var fileInfo = info as FileInfo;
            if (fileInfo != null)
            {
                result.Headers.LastModified.Value = fileInfo.LastWriteTimeUtc;
                result.Headers.ContentLength.Value = fileInfo.Length;
            }

            return result;
        }
コード例 #2
0
ファイル: StaticResponse.cs プロジェクト: c4net/OWIN-Static
 public static StaticResponse Redirect(string location)
 {
     var result = new StaticResponse(Constants.Http.StatusCodes.Redirection.Found, "Redirecting to " + location);
     result.Headers.Location.Value = location;
     return result;
 }
コード例 #3
0
 private Task CacheResponseAndSend(StaticResponse staticResponse, IOwinContext ctx)
 {
     if (cached)
     {
         return CachedResponse.CreateAsync(staticResponse, ctx.CallCancelled)
                 .ContinueWith(
                     task =>
                     {
                         task.Wait(ctx.CallCancelled);
                         CacheSet(ctx.Request.Location.FullPath, task.Result);
                         return SendResponse(task.Result, ctx);
                     }, TaskContinuationOptions.ExecuteSynchronously)
                 .Unwrap();
     }
     return SendResponse(staticResponse, ctx);
 }
コード例 #4
0
ファイル: StaticResponse.cs プロジェクト: c4net/OWIN-Static
 public static StaticResponse MethodNotAllowed(params string[] allowedMethods)
 {
     var result = new StaticResponse(Constants.Http.StatusCodes.ClientError.MethodNotAllowed);
     result.Headers.Allow.EnumValues = allowedMethods;
     return result;
 }
コード例 #5
0
 private Task SendResponse(StaticResponse staticResponse, IOwinContext ctx)
 {
     return ProcessResponseStream(staticResponse, staticResponse.Body, ctx);
 }