/** * Send an HTTP HEAD request to get the deposit's host to get an estimate * of the download size. * * @param type $deposit * * @throws Exception */ protected function checkSize(Deposit $deposit) { $client = $this->getClient(); try { $head = $client->head($deposit->getUrl()); if ($head->getStatusCode() !== 200) { throw new Exception("HTTP HEAD request cannot check file size: HTTP {$head->getStatusCode()} - {$head->getReasonPhrase()} - {$deposit->getUrl()}"); } $size = $head->getHeader('Content-Length'); if ($size === null || $size === '') { throw new Exception("HTTP HEAD response does not include file size - {$deposit->getUrl()}"); } $expectedSize = $deposit->getSize() * 1000; if (abs($expectedSize - $size) / $size > self::FILE_SIZE_THRESHOLD) { $deposit->addErrorLog("Expected file size {$expectedSize} is not close to reported size {$size}"); $this->logger->warning("Harvest - {$deposit->getUrl()} - Expected file size {$expectedSize} is not close to reported size {$size}"); } } catch (RequestException $e) { $response = $e->getResponse(); if ($response !== null) { $this->logger->critical($e->getResponse()->getStatusCode() . ' ' . $e->getResponse()->getReasonPhrase()); } else { $this->logger->critical($e->getMessage()); } throw $e; } }
public function testSize() { $this->assertEquals(123, $this->deposit->getSize()); }