From acf06f18ed6fbb6fd06e964de61678ffb46e86b6 Mon Sep 17 00:00:00 2001 From: KSV Date: Thu, 12 Sep 2013 14:45:13 +0530 Subject: [PATCH] Add explicit no-cache directive for bootstrap updates 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. --- AdobeHDS.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/AdobeHDS.php b/AdobeHDS.php index 3b779f5..cc72a01 100644 --- a/AdobeHDS.php +++ b/AdobeHDS.php @@ -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) @@ -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") @@ -617,6 +624,9 @@ function UpdateBootstrapInfo($cc, $bootstrapUrl) usleep(4000000); } } + + // Restore original headers + $cc->headers = $headers; } function ParseBootstrapBox($bootstrapInfo, $pos)