Esempio n. 1
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);
            }
        }
 public void FindBundleContainingPathWithWrongPathReturnsNull()
 {
     var collection = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>())
     {
         new TestableBundle("~/test")
     };
     var actualBundle = collection.FindBundlesContainingPath("~/WRONG");
     actualBundle.ShouldBeEmpty();
 }
 public void FindBundleContainingPathOfBundleWherePathIsMissingRootPrefixReturnsTheBundle()
 {
     var expectedBundle = new TestableBundle("~/test");
     var collection = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>())
     {
         expectedBundle
     };
     var actualBundle = collection.FindBundlesContainingPath("test").First();
     actualBundle.ShouldBeSameAs(expectedBundle);
 }
Esempio n. 4
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));
            }
        }
 public void FindBundleContainingPathOfAssetReturnsTheBundle()
 {
     var expectedBundle = new TestableBundle("~/test");
     var asset = new Mock<IAsset>();
     AssetAcceptsVisitor(asset);
     asset.SetupGet(a => a.Path).Returns("~/test/test.js");
     expectedBundle.Assets.Add(asset.Object);
     var bundles = new BundleCollection(new CassetteSettings(), Mock.Of<IFileSearchProvider>(), Mock.Of<IBundleFactoryProvider>())
     {
         expectedBundle
     };
     var actualBundle = bundles.FindBundlesContainingPath("~/test/test.js").First();
     actualBundle.ShouldBeSameAs(expectedBundle);
 }
Esempio n. 6
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) });
         }
     }
 }
Esempio n. 7
0
 Bundle FindBundle(string path)
 {
     Trace.Source.TraceInformation("Handling bundle request for \"{0}\".", path);
     return(bundles.FindBundlesContainingPath(path).OfType <T>().FirstOrDefault());
 }