/// <summary> /// Creates a new module script provider that loads modules against a set of /// privileged and fallback URIs. /// </summary> /// <remarks> /// Creates a new module script provider that loads modules against a set of /// privileged and fallback URIs. It will use the specified heuristic cache /// expiry calculator and security domain provider. /// </remarks> /// <param name="privilegedUris"> /// an iterable providing the privileged URIs. Can be /// null if no privileged URIs are used. /// </param> /// <param name="fallbackUris"> /// an iterable providing the fallback URIs. Can be /// null if no fallback URIs are used. /// </param> /// <param name="urlConnectionExpiryCalculator"> /// the calculator object for heuristic /// calculation of the resource expiry, used when no expiry is provided by /// the server of the resource. Can be null, in which case the maximum age /// of cached entries without validation will be zero. /// </param> /// <param name="urlConnectionSecurityDomainProvider"> /// object that provides security /// domain objects for the loaded sources. Can be null, in which case the /// loaded sources will have no security domain associated with them. /// </param> public UrlModuleSourceProvider(IEnumerable<Uri> privilegedUris, IEnumerable<Uri> fallbackUris, UrlConnectionExpiryCalculator urlConnectionExpiryCalculator, UrlConnectionSecurityDomainProvider urlConnectionSecurityDomainProvider) { this.privilegedUris = privilegedUris; this.fallbackUris = fallbackUris; this.urlConnectionExpiryCalculator = urlConnectionExpiryCalculator; this.urlConnectionSecurityDomainProvider = urlConnectionSecurityDomainProvider; }
/// <exception cref="System.IO.IOException"></exception> internal virtual bool UpdateValidator(URLConnection urlConnection, long request_time, UrlConnectionExpiryCalculator urlConnectionExpiryCalculator) { bool isResourceChanged = IsResourceChanged(urlConnection); if (!isResourceChanged) { expiry = CalculateExpiry(urlConnection, request_time, urlConnectionExpiryCalculator); } return isResourceChanged; }
private long CalculateExpiry(URLConnection urlConnection, long request_time, UrlConnectionExpiryCalculator urlConnectionExpiryCalculator) { if ("no-cache".Equals(urlConnection.GetHeaderField("Pragma"))) { return 0L; } string cacheControl = urlConnection.GetHeaderField("Cache-Control"); if (cacheControl != null) { if (cacheControl.IndexOf("no-cache") != -1) { return 0L; } int max_age = GetMaxAge(cacheControl); if (-1 != max_age) { long response_time = Runtime.CurrentTimeMillis(); long apparent_age = Math.Max(0, response_time - urlConnection.GetDate()); long corrected_received_age = Math.Max(apparent_age, urlConnection.GetHeaderFieldInt("Age", 0) * 1000L); long response_delay = response_time - request_time; long corrected_initial_age = corrected_received_age + response_delay; long creation_time = response_time - corrected_initial_age; return max_age * 1000L + creation_time; } } long explicitExpiry = urlConnection.GetHeaderFieldDate("Expires", -1L); if (explicitExpiry != -1L) { return explicitExpiry; } return urlConnectionExpiryCalculator == null ? 0L : urlConnectionExpiryCalculator.CalculateExpiry(urlConnection); }
public URLValidator(Uri uri, URLConnection urlConnection, long request_time, UrlConnectionExpiryCalculator urlConnectionExpiryCalculator) { this.uri = uri; this.lastModified = urlConnection.GetLastModified(); this.entityTags = GetEntityTags(urlConnection); expiry = CalculateExpiry(urlConnection, request_time, urlConnectionExpiryCalculator); }