private void updateRange (CacheEntry<HttpHeader, HttpHeader> old,
HttpHeader response,
PartialCacher pc,
Cache<HttpHeader, HttpHeader> cache) {
HttpHeader oldRequest = old.getKey ();
HttpHeader oldResponse = old.getDataHook (cache);
String cr = oldResponse.getHeader ("Content-Range");
if (cr == null) {
String cl = oldResponse.getHeader ("Content-Length");
if (cl != null) {
long size = Long.parseLong (cl);
cr = "bytes 0-" + (size - 1) + "/" + size;
}
}
ContentRangeParser crp = new ContentRangeParser (cr, getLogger ());
if (crp.isValid ()) {
long start = crp.getStart ();
long end = crp.getEnd ();
long total = crp.getTotal ();
String t = total < 0 ? "*" : Long.toString (total);
if (end == pc.getStart () - 1) {
oldRequest.setHeader ("Range",
"bytes=" + start + "-" + end);
oldResponse.setHeader ("Content-Range",
"bytes " + start + "-" +
pc.getEnd () + "/" + t);
} else {
oldRequest.addHeader ("Range",
"bytes=" + start + "-" + end);
oldResponse.addHeader ("Content-Range",
"bytes " + start + "-" +
pc.getEnd () + "/" + t);
}
cache.entryChanged (old, oldRequest, oldResponse);
}