Skip to content

Commit

Permalink
Add explicit no-cache directive for bootstrap updates
Browse files Browse the repository at this point in the history
This fixes problems with some buggy servers which are returning HTTP 304 response instead of HTTP 200 response even when no cached copy is available with client or when client makes the initial bootstrap request.
  • Loading branch information
K-S-V committed Sep 12, 2013
1 parent 718f65b commit acf06f1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions AdobeHDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class cURL
function cURL($cookies = true, $cookie = 'Cookies.txt', $compression = 'gzip', $proxy = '')
{
$this->headers = $this->headers();
$this->user_agent = 'Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0';
$this->user_agent = 'Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0';
$this->compression = $compression;
$this->cookies = $cookies;
if ($this->cookies == true)
Expand Down Expand Up @@ -581,29 +581,36 @@ function ParseManifest($cc, $parentManifest)
if (isset($this->media['bootstrapUrl']))
{
$this->bootstrapUrl = $this->media['bootstrapUrl'];
if ($cc->get($this->bootstrapUrl) != 200)
LogError("Failed to get bootstrap info");
$bootstrapInfo = $cc->response;
$this->UpdateBootstrapInfo($cc, $this->bootstrapUrl);
}
else
{
$bootstrapInfo = $this->media['bootstrap'];
ReadBoxHeader($bootstrapInfo, $pos, $boxType, $boxSize);
if ($boxType == "abst")
$this->ParseBootstrapBox($bootstrapInfo, $pos);
else
LogError("Failed to parse bootstrap info");
ReadBoxHeader($bootstrapInfo, $pos, $boxType, $boxSize);
if ($boxType == "abst")
$this->ParseBootstrapBox($bootstrapInfo, $pos);
else
LogError("Failed to parse bootstrap info");
}
}

function UpdateBootstrapInfo($cc, $bootstrapUrl)
{
$fragNum = $this->fragCount;
$retries = 0;

// Backup original headers and add no-cache directive for fresh bootstrap info
$headers = $cc->headers;
$cc->headers[] = "Cache-Control: no-cache";
$cc->headers[] = "Pragma: no-cache";

while (($fragNum == $this->fragCount) and ($retries < 30))
{
$bootstrapPos = 0;
LogDebug("Updating bootstrap info, Available fragments: " . $this->fragCount);
if ($cc->get($bootstrapUrl) != 200)
LogError("Failed to refresh bootstrap info");
$status = $cc->get($bootstrapUrl);
if ($status != 200)
LogError("Failed to refresh bootstrap info, Status: " . $status);
$bootstrapInfo = $cc->response;
ReadBoxHeader($bootstrapInfo, $bootstrapPos, $boxType, $boxSize);
if ($boxType == "abst")
Expand All @@ -617,6 +624,9 @@ function UpdateBootstrapInfo($cc, $bootstrapUrl)
usleep(4000000);
}
}

// Restore original headers
$cc->headers = $headers;
}

function ParseBootstrapBox($bootstrapInfo, $pos)
Expand Down

0 comments on commit acf06f1

Please sign in to comment.