示例#1
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);
            }
        }
示例#2
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);
            }
        }
示例#3
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);
            }
        }