AddFileDependency() public method

public AddFileDependency ( string filename ) : void
filename string
return void
        internal static void ProcessRequestInternal(HttpContext context, string overrideVirtualPath)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            if (!ProcessRequestForNonMapPathBasedVirtualFile(request, response, overrideVirtualPath))
            {
                string path;
                string physicalPath;
                if (overrideVirtualPath == null)
                {
                    path         = request.Path;
                    physicalPath = request.PhysicalPath;
                }
                else
                {
                    path         = overrideVirtualPath;
                    physicalPath = request.MapPath(overrideVirtualPath);
                }
                FileInfo info         = GetFileInfo(path, physicalPath, response);
                DateTime lastModified = new DateTime(info.LastWriteTime.Year, info.LastWriteTime.Month, info.LastWriteTime.Day, info.LastWriteTime.Hour, info.LastWriteTime.Minute, info.LastWriteTime.Second, 0);
                DateTime now          = DateTime.Now;
                if (lastModified > now)
                {
                    lastModified = new DateTime(now.Ticks - (now.Ticks % 0x989680L));
                }
                string etag   = GenerateETag(context, lastModified, now);
                long   length = info.Length;
                string str4   = request.Headers["Range"];
                if (!StringUtil.StringStartsWithIgnoreCase(str4, "bytes") || !ProcessRangeRequest(context, physicalPath, length, str4, etag, lastModified))
                {
                    SendFile(physicalPath, 0L, length, length, context);
                    response.ContentType = MimeMapping.GetMimeMapping(physicalPath);
                    response.AppendHeader("Accept-Ranges", "bytes");
                    response.AddFileDependency(physicalPath);
                    response.Cache.SetIgnoreRangeRequests();
                    response.Cache.SetExpires(DateTime.Now.AddDays(1.0));
                    response.Cache.SetLastModified(lastModified);
                    response.Cache.SetETag(etag);
                    response.Cache.SetCacheability(HttpCacheability.Public);
                }
            }
        }
 public override void AddFileDependency(string filename)
 {
     _httpResponse.AddFileDependency(filename);
 }
Example #3
0
		public void Methods_Deny_Unrestricted ()
		{
			HttpResponse response = new HttpResponse (writer);
			response.AddCacheItemDependencies (new ArrayList ());
			response.AddCacheItemDependency (String.Empty);
			response.AddFileDependencies (new ArrayList ());
			response.AddFileDependency (fname);
			response.AddCacheDependency (new CacheDependency[0]);
			response.AddCacheItemDependencies (new string [0]);
			response.AddFileDependencies (new string [0]);

			try {
				response.AppendCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				Assert.IsNull (response.ApplyAppPathModifier (null), "ApplyAppPathModifier");
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Clear ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearContent ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearHeaders ();
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Redirect ("http://www.mono-project.com");
			}
			catch (NullReferenceException) {
				// ms 
			}
			try {
				response.Redirect ("http://www.mono-project.com", false);
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.SetCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			response.Write (String.Empty);
			response.Write (Char.MinValue);
			response.Write (new char[0], 0, 0);
			response.Write (this);
			response.WriteSubstitution (new HttpResponseSubstitutionCallback (Callback));

			response.Flush ();

			response.Close ();

			try {
				response.End ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		}
Example #4
0
 public override void AddFileDependency(string filename)
 {
     w.AddFileDependency(filename);
 }
        void BuildFileItemResponse(HttpContext context,
                                   string fileName,
                                   long fileSize,
                                   DateTime lastModifiedTime,
                                   string strETag)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;
            bool         fCache   = false;
            string       strRange;
            int          cbCacheThreshold = DEFAULT_CACHE_THRESHOLD;
            bool         fIsRangeRequest  = false;

            //
            // Get the Range: header if it exists
            //

            strRange = request.Headers["Range"];
            if (strRange != null)
            {
                if (strRange.ToLower(CultureInfo.InvariantCulture).StartsWith("bytes"))
                {
                    fIsRangeRequest = true;
                }
            }

            //
            // Give the range code a first crack at sending the ranges.  If
            // the Range: header is syntactically invalid, then we will fall
            // thru as if the Range: header was not present.
            //

            if (fIsRangeRequest &&
                !SendEntireEntity(context,
                                  strETag,
                                  lastModifiedTime))
            {
                // At this point we know that based on "If-Range"
                // (if provided) we may not send the entire entity.

#if  SUPPORT_HTTP_RANGE_REQUESTS
                if (RangeSupport.ProcessRangeRequest(context,
                                                     strRange,
                                                     fileName,
                                                     fileSize))
                {
                    //
                    // If ProcessRangeRequest() returned true, then it
                    // handled the range somehow (either sending it back
                    // with a 206 or sent a 416
                    //

                    response.Cache.SetNoServerCaching();

                    return;
                }
#endif
                //
                // Fall thru.  The request is now cacheable again
                //
            }

            if (fileSize <= cbCacheThreshold &&
                !request.RequestType.Equals("(GETSOURCE)") &&
                !request.RequestType.Equals("(HEADSOURCE)"))
            {
                fCache = true;
            }

            //
            // Ask ASP to open the file contents and cache them
            // (hence the second parameter to WriteFile())
            //

            response.WriteFile(fileName, fCache);

            //
            // Specify content type. Use extension to do the mapping
            //

            response.ContentType = MimeMapping.GetMimeMapping(fileName);

            //
            // Static file handler supports byte ranges (duh)
            //

            response.AppendHeader("Accept-Ranges", "bytes");

            //
            // If we are caching, the instruct the ASP output cache to
            // to cache the result.
            //

            if (fCache)
            {
                //
                // Set a validation handler to check to avoid serving from
                // ASP.NET output cache when Range or Translate:f
                //


                response.Cache.AddValidationCallback(
                    new HttpCacheValidateHandler(this.CacheValidateHandler),
                    null);

                //
                //
                // We want to flush cache entry when static file has changed
                //

                response.AddFileDependency(fileName);

                //
                // Set an expires in the future.
                //

                response.Cache.SetExpires(DateTime.Now.AddDays(1));
            }
        }
Example #6
0
        internal static void ProcessRequestInternal(HttpContext context, string overrideVirtualPath)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;
            string       virtualPathWithPathInfo;
            string       physicalPath;
            FileInfo     fileInfo;
            long         fileLength;
            DateTime     lastModifiedInUtc;
            string       etag;
            string       rangeHeader;

            // custom virtual path providers that don't yeild a MapPathBasedVirtualFile
            // are a special case, and do not support TransmitFile, WriteFile, Range requests,
            // or the cache policy that we apply below
            if (ProcessRequestForNonMapPathBasedVirtualFile(request, response, overrideVirtualPath))
            {
                return;
            }

            if (overrideVirtualPath == null)
            {
                virtualPathWithPathInfo = request.Path;
                physicalPath            = request.PhysicalPath;
            }
            else
            {
                virtualPathWithPathInfo = overrideVirtualPath;
                physicalPath            = request.MapPath(overrideVirtualPath);
            }

            Debug.Trace("StaticFileHandler", "Path= " + virtualPathWithPathInfo + ", PhysicalPath= " + physicalPath);

            fileInfo = GetFileInfo(virtualPathWithPathInfo, physicalPath, response);

            // Determine Last Modified Time.  We might need it soon
            // if we encounter a Range: and If-Range header
            // Using UTC time to avoid daylight savings time
            lastModifiedInUtc = new DateTime(fileInfo.LastWriteTimeUtc.Year,
                                             fileInfo.LastWriteTimeUtc.Month,
                                             fileInfo.LastWriteTimeUtc.Day,
                                             fileInfo.LastWriteTimeUtc.Hour,
                                             fileInfo.LastWriteTimeUtc.Minute,
                                             fileInfo.LastWriteTimeUtc.Second,
                                             0,
                                             DateTimeKind.Utc);

            // Because we can't set a "Last-Modified" header to any time
            // in the future, check the last modified time and set it to
            // DateTime.Now if it's in the future.
            // This is to fix VSWhidbey #402323
            DateTime utcNow = DateTime.UtcNow;

            if (lastModifiedInUtc > utcNow)
            {
                // use 1 second resolution
                lastModifiedInUtc = new DateTime(utcNow.Ticks - (utcNow.Ticks % TimeSpan.TicksPerSecond), DateTimeKind.Utc);
            }

            etag       = GenerateETag(context, lastModifiedInUtc, utcNow);
            fileLength = fileInfo.Length;

            // is this a Range request?
            rangeHeader = request.Headers["Range"];
            if (StringUtil.StringStartsWithIgnoreCase(rangeHeader, "bytes") &&
                ProcessRangeRequest(context,
                                    physicalPath,
                                    fileLength,
                                    rangeHeader,
                                    etag,
                                    lastModifiedInUtc))
            {
                return;
            }

            // if we get this far, we're sending the entire file
            SendFile(physicalPath, 0, fileLength, fileLength, context);

            // Specify content type. Use extension to do the mapping
            response.ContentType = MimeMapping.GetMimeMapping(physicalPath);
            // Static file handler supports byte ranges
            response.AppendHeader("Accept-Ranges", "bytes");
            // We want to flush cache entry when static file has changed
            response.AddFileDependency(physicalPath);
            // Set IgnoreRangeRequests to avoid serving Range requests from the output cache.
            // Note that the kernel cache always ignores Range requests.
            response.Cache.SetIgnoreRangeRequests();
            // Set an expires in the future.
            response.Cache.SetExpires(utcNow.AddDays(1));
            // always set Last-Modified
            response.Cache.SetLastModified(lastModifiedInUtc);
            // always set ETag
            response.Cache.SetETag(etag);
            // always set Cache-Control to public
            response.Cache.SetCacheability(HttpCacheability.Public);
        }