System.Net.Cache.FtpRequestCacheValidator.ValidateRequest C# (CSharp) Method

ValidateRequest() protected method

protected ValidateRequest ( ) : CacheValidationStatus
return CacheValidationStatus
        protected internal override CacheValidationStatus ValidateRequest()
        {
            // cleanup context after previous  request
            ZeroPrivateVars();

            if (Request is HttpWebRequest)
            {
                m_HttpProxyMode = true;
                if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_ftp_proxy_doesnt_support_partial));
                return base.ValidateRequest();
            }

            if (Policy.Level == RequestCacheLevel.BypassCache)
                return CacheValidationStatus.DoNotUseCache;

            string method = Request.Method.ToUpper(CultureInfo.InvariantCulture);
            if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_ftp_method, method));

            switch (method) {
                case WebRequestMethods.Ftp.DownloadFile:  RequestMethod = HttpMethod.Get;   break;
                case WebRequestMethods.Ftp.UploadFile:    RequestMethod = HttpMethod.Put;break;
                case WebRequestMethods.Ftp.AppendFile:    RequestMethod = HttpMethod.Put;break;
                case WebRequestMethods.Ftp.Rename:        RequestMethod = HttpMethod.Put;break;
                case WebRequestMethods.Ftp.DeleteFile:    RequestMethod = HttpMethod.Delete;break;

                default:        RequestMethod = HttpMethod.Other;    break;
            }

            if ((RequestMethod != HttpMethod.Get || !((FtpWebRequest)Request).UseBinary) && Policy.Level == RequestCacheLevel.CacheOnly)
            {
                // Throw because the request must hit the wire and it's cache-only policy
                FailRequest(WebExceptionStatus.RequestProhibitedByCachePolicy);
            }

            if (method != WebRequestMethods.Ftp.DownloadFile)
                return CacheValidationStatus.DoNotTakeFromCache;

            if (!((FtpWebRequest)Request).UseBinary)
            {
                if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_ftp_supports_bin_only));
                return CacheValidationStatus.DoNotUseCache;
            }

            if (Policy.Level >= RequestCacheLevel.Reload)
                return CacheValidationStatus.DoNotTakeFromCache;

            return CacheValidationStatus.Continue;
        }