示例#1
0
 public void ProcessRequest(string path)
 {
     httpContext.DisableHtmlRewriting();
     using (bundles.GetReadLock())
     {
         var bundle = FindBundle(path);
         if (bundle == null)
         {
             Trace.Source.TraceInformation("Bundle not found \"{0}\".", path);
             response.StatusCode = 404;
         }
         else
         {
             var actualETag = "\"" + bundle.Hash.ToHexString() + "\"";
             var givenETag  = request.Headers["If-None-Match"];
             if (givenETag == actualETag)
             {
                 SendNotModified(actualETag);
             }
             else
             {
                 SendBundle(bundle, actualETag);
             }
         }
     }
 }
示例#2
0
        public Response ProcessRequest(NancyContext context, string path)
        {
            var pattern = new Regex(@"~?/?[a-z]{5,}/[a-f0-9]{10,}/", RegexOptions.IgnoreCase);

            path = pattern.Replace(path, "/");

            using (bundles.GetReadLock())
            {
                var bundle = bundles.FindBundlesContainingPath(path).OfType <TBundle>().FirstOrDefault();
                if (bundle == null)
                {
                    logger.Info("ProcessRequest : Bundle '{0}' not found", path);
                    return(new HtmlResponse(HttpStatusCode.NotFound));
                }

                var actualETag = "\"" + bundle.Hash.ToHexString() + "\"";
                var givenETag  = context.Request.Headers["If-None-Match"];

                if (givenETag.Equals(actualETag))
                {
                    logger.Info("ProcessRequest : Bundle '{0}' not modified", path);
                    var notModified = new HtmlResponse(HttpStatusCode.NotModified);
                    notModified.ContentType = bundle.ContentType;
                    return(notModified);
                }

                logger.Info("ProcessRequest : Bundle '{0}' returned", path);
                var response = new StreamResponse(bundle.OpenStream, bundle.ContentType);
                response.WithHeader("ETag", actualETag);
                return(response);
            }
        }
示例#3
0
        public Response ProcessRequest(NancyContext context, string path)
        {
            path = string.Concat("~", path.Substring(PathPrefix.Length));

            using (bundles.GetReadLock())
            {
                Bundle bundle;
                IAsset asset;
                if (!bundles.TryGetAssetByPath(path, out asset, out bundle))
                {
                    logger.Info("ProcessRequest : Asset '{0}' not found", path);
                    return(new HtmlResponse(HttpStatusCode.NotFound));
                }

                var actualETag = "\"" + asset.Hash.ToHexString() + "\"";
                var givenETag  = context.Request.Headers["If-None-Match"];

                if (givenETag.Equals(actualETag))
                {
                    logger.Info("ProcessRequest : Asset '{0}' not modified", path);
                    var notModified = new HtmlResponse(HttpStatusCode.NotModified);
                    notModified.ContentType = bundle.ContentType;
                    return(notModified);
                }

                logger.Info("ProcessRequest : Asset '{0}' returned", path);
                var response = new StreamResponse(asset.OpenStream, bundle.ContentType);
                response.WithHeader("ETag", actualETag);
                return(response);
            }
        }
示例#4
0
 public IHtmlString RequireJsScript(params string[] initialModules)
 {
     using (bundles.GetReadLock())
     {
         return(new HtmlString(
                    ConfigScriptElement() +
                    MainScriptElements() +
                    InitScriptElement(initialModules)
                    ));
     }
 }
示例#5
0
        public string Url <T>(string bundlePath)
            where T : Bundle
        {
            using (bundles.GetReadLock())
            {
                var bundle = bundles.FindBundlesContainingPath(bundlePath).OfType <T>().FirstOrDefault();
                if (bundle == null)
                {
                    throw new ArgumentException(string.Format("Bundle not found with path \"{0}\".", bundlePath));
                }

                return(urlGenerator.CreateBundleUrl(bundle));
            }
        }
示例#6
0
        public void ProcessRequest(string path)
        {
            Trace.Source.TraceInformation("Handling asset request for path \"{0}\".", path);
            requestContext.HttpContext.DisableHtmlRewriting();
            using (bundles.GetReadLock())
            {
                Bundle bundle;
                IAsset asset;
                if (!bundles.TryGetAssetByPath(path, out asset, out bundle))
                {
                    Trace.Source.TraceInformation("Bundle asset not found with path \"{0}\".", path);
                    response.StatusCode = (int)HttpStatusCode.NotFound;
                    throw new HttpException((int)HttpStatusCode.NotFound, "Asset not found");
                }

                SendAsset(bundle, asset);
            }
        }
示例#7
0
 public IEnumerable <string> GetStylesheetUrls(string path)
 {
     using (bundles.GetReadLock())
     {
         var bundle = bundles.FindBundlesContainingPath(path).OfType <StylesheetBundle>().FirstOrDefault();
         if (bundle == null)
         {
             return(Enumerable.Empty <string>());
         }
         if (settings.IsDebuggingEnabled)
         {
             return(bundle.Assets.Select(urlGenerator.CreateAssetUrl));
         }
         else
         {
             return(new[] { urlGenerator.CreateBundleUrl(bundle) });
         }
     }
 }
示例#8
0
        public void ProcessRequest(string path)
        {
            Trace.Source.TraceInformation("Handling asset request for path \"{0}\".", path);
            requestContext.HttpContext.DisableHtmlRewriting();
            var response = requestContext.HttpContext.Response;

            using (bundles.GetReadLock())
            {
                Bundle bundle;
                IAsset asset;
                if (!bundles.TryGetAssetByPath(path, out asset, out bundle))
                {
                    Trace.Source.TraceInformation("Bundle asset not found with path \"{0}\".", path);
                    NotFound(response);
                    return;
                }

                var request = requestContext.HttpContext.Request;
                SendAsset(request, response, bundle, asset);
            }
        }
        public bool IsValid(string assetPath, DateTime asOfDateTime)
        {
            using (bundles.GetReadLock())
            {
                Bundle bundle;
                IAsset asset;

                if (!bundles.TryGetAssetByPath(assetPath, out asset, out bundle))
                {
                    return(false);
                }

                var resourceAsset = asset as ResourceAsset;
                if (resourceAsset == null)
                {
                    return(true);
                }

                var lastModified = File.GetLastWriteTimeUtc(resourceAsset.Assembly.Location);
                return(lastModified <= asOfDateTime);
            }
        }