protected internal override CacheValidationStatus UpdateCache()
{
if (HttpProxyMode)
return base.UpdateCache();
// An combined cace+wire response is not supported if user has specified a restart offset.
CacheStreamOffset = 0L;
if (RequestMethod == HttpMethod.Other)
{
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_not_updated_based_on_policy, Request.Method));
return CacheValidationStatus.DoNotUpdateCache;
}
if (ValidationStatus == CacheValidationStatus.RemoveFromCache) {
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_removed_existing_invalid_entry));
return CacheValidationStatus.RemoveFromCache;
}
if (Policy.Level == RequestCacheLevel.CacheOnly) {
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_not_updated_based_on_policy, Policy.ToString()));
return CacheValidationStatus.DoNotUpdateCache;
}
FtpWebResponse resp = Response as FtpWebResponse;
if (resp == null)
{
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_not_updated_because_no_response));
return CacheValidationStatus.DoNotUpdateCache;
}
//
// Check on cache removal based on the request method
//
if (RequestMethod == HttpMethod.Delete || RequestMethod == HttpMethod.Put)
{
if (RequestMethod == HttpMethod.Delete ||
resp.StatusCode == FtpStatusCode.OpeningData ||
resp.StatusCode == FtpStatusCode.DataAlreadyOpen ||
resp.StatusCode == FtpStatusCode.FileActionOK ||
resp.StatusCode == FtpStatusCode.ClosingData)
{
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_removed_existing_based_on_method, Request.Method));
return CacheValidationStatus.RemoveFromCache;
}
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_existing_not_removed_because_unexpected_response_status, (int)resp.StatusCode, resp.StatusCode.ToString()));
return CacheValidationStatus.DoNotUpdateCache;
}
if (Policy.Level == RequestCacheLevel.NoCacheNoStore) {
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_removed_existing_based_on_policy, Policy.ToString()));
return CacheValidationStatus.RemoveFromCache;
}
if (ValidationStatus == CacheValidationStatus.ReturnCachedResponse)
{
// have a response still returning from cache means just revalidated the entry.
return UpdateCacheEntryOnRevalidate();
}
if (resp.StatusCode != FtpStatusCode.OpeningData
&& resp.StatusCode != FtpStatusCode.DataAlreadyOpen
&& resp.StatusCode != FtpStatusCode.ClosingData)
{
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_not_updated_based_on_ftp_response_status, FtpStatusCode.OpeningData.ToString() + "|" + FtpStatusCode.DataAlreadyOpen.ToString() + "|" + FtpStatusCode.ClosingData.ToString(), resp.StatusCode.ToString()));
return CacheValidationStatus.DoNotUpdateCache;
}
// Check on no-update or cache removal if restart action has invalidated existing cache entry
if (((FtpWebRequest)Request).ContentOffset != 0L)
{
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_update_not_supported_for_ftp_restart, ((FtpWebRequest)Request).ContentOffset.ToString(CultureInfo.InvariantCulture)));
if (CacheEntry.LastModifiedUtc != DateTime.MinValue && resp.LastModified.ToUniversalTime() != CacheEntry.LastModifiedUtc)
{
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_removed_entry_because_ftp_restart_response_changed, CacheEntry.LastModifiedUtc.ToString("r", CultureInfo.InvariantCulture), resp.LastModified.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture)));
return CacheValidationStatus.RemoveFromCache;
}
return CacheValidationStatus.DoNotUpdateCache;
}
return UpdateCacheEntryOnStore();
}