private static bool TryConditionalRangeRequest(HttpRequestCacheValidator ctx) {
//
// The response is partially cached (that has been checked before calling this method)
//
if (ctx.CacheEntry.StreamSize >= Int32.MaxValue) {
//This is a restriction of HttpWebRequest implementation as on 01/28/03
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_entry_size_too_big, ctx.CacheEntry.StreamSize));
return false;
}
/*
If the entity tag given in the If-Range header matches the current
entity tag for the entity, then the server SHOULD provide the
specified sub-range of the entity using a 206 (Partial content)
response. If the entity tag does not match, then the server SHOULD
return the entire entity using a 200 (OK) response.
*/
string str = ctx.CacheHeaders.ETag;
if (str != null) {
ctx.Request.Headers[HttpKnownHeaderNames.IfRange] = str;
ctx.RequestIfHeader1 = HttpKnownHeaderNames.IfRange;
ctx.RequestValidator1 =str;
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_condition_if_range, ctx.Request.Headers[HttpKnownHeaderNames.IfRange]));
return true;
}
/*
- If only a Last-Modified value has been provided by an HTTP/1.0
origin server, MAY use that value in subrange cache-conditional
requests (using If-Unmodified-Since:). The user agent SHOULD
provide a way to disable this, in case of difficulty.
*/
if (ctx.CacheEntry.LastModifiedUtc != DateTime.MinValue)
{
str = ctx.CacheEntry.LastModifiedUtc.ToString("r", CultureInfo.InvariantCulture);
if (ctx.CacheHttpVersion.Major == 1 && ctx.CacheHttpVersion.Minor == 0)
{
// Well If-Unmodified-Since would require an additional request in case it WAS modified
// A User may want to excerise this path without relying on our implementation.
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_conditional_range_not_implemented_on_http_10));
return false;
/*
//Http == 1.0
ctx.Request.Headers[HttpKnownHeaderNames.IfUnmodifiedSince] = str;
ctx.RequestIfHeader1 = HttpKnownHeaderNames.IfUnmodifiedSince;
ctx.RequestValidator1 = str;
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, "Request Condition = If-Unmodified-Since:" + ctx.Request.Headers[HttpKnownHeaderNames.IfUnmodifiedSince]);
return true;
*/
}
else
{
//Http > 1.0
ctx.Request.Headers[HttpKnownHeaderNames.IfRange] = str;
ctx.RequestIfHeader1 = HttpKnownHeaderNames.IfRange;
ctx.RequestValidator1 =str;
if(Logging.On)Logging.PrintInfo(Logging.RequestCache, SR.GetString(SR.net_log_cache_condition_if_range, ctx.Request.Headers[HttpKnownHeaderNames.IfRange]));
return true;
}
}
if(Logging.On)Logging.PrintWarning(Logging.RequestCache, SR.GetString(SR.net_log_cache_cannot_construct_conditional_range_request));
//Cannot construct a conditional request
return false;
}