public function validate(Response $response) { if ($response->getStatus() <= $this->maxStatusCode) { if ($response->hasHeader('Pragma') && 'no-cache' === $response->getHeader('Pragma')[0]) { throw new ValidationFailedException('pragma:no-cache was found'); } if ($response->hasHeader('Cache-Control') && false !== strpos($response->getHeader('Cache-Control')[0], 'no-cache')) { throw new ValidationFailedException('cache-control:no-cache was found'); } } }
public function validate(Response $response) { if ($response->getStatus() <= $this->maxStatusCode) { if ($response->hasHeader('Expires')) { $expireRaw = preg_replace('/[^A-Za-z0-9\\-\\/,]/', '', $response->getHeader('Expires')[0]); if ($expireRaw !== '') { $expires = strtotime($response->getHeader('Expires')[0]); if ($expires < time()) { throw new ValidationFailedException('expires in the past'); } } } } }
public function validate(Response $response) { if ($response->getStatus() <= $this->maxStatusCode) { if ($response->hasHeader('Cache-Control') && false !== strpos($response->getHeader('Cache-Control')[0], 'max-age=0')) { throw new ValidationFailedException('max-age=0 was found'); } } }
public function doValidation(Response $response) { if (strpos($response->getContentType(), 'image') === false && strpos($response->getContentType(), 'pdf') === false && strlen((string) $response->getBody()) >= $this->minFileSize) { if (!$response->hasHeader('Content-Encoding') || $response->getHeader('Content-Encoding')[0] !== 'gzip') { throw new ValidationFailedException('gzip compression not active'); } } }
public function doValidation(Response $response) { // @todo the test should not fail with the first not found header foreach ($this->checkedHeaders as $headerConfig) { if (!$response->hasHeader($headerConfig['key'])) { throw new ValidationFailedException('Header not found (' . $headerConfig['key'] . ')'); } $currentValue = $response->getHeader($headerConfig['key'])[0]; if (!preg_match('^' . $headerConfig['value'] . '^', $currentValue, $matches)) { throw new ValidationFailedException('Header "' . $headerConfig['key'] . '" does not match "' . $headerConfig['value'] . '". Current value is "' . $currentValue . '"'); } } }
public function testResponse() { $testBody = 'TestBodyWith<strong>special</strong>Chäräctörs'; $testHeader = HeadersParser::parse(['Header1' => 'Test Header']); $testStatus = 200; $testUri = new Uri('http://smoke.phmlabs.com'); $testRequest = new Request($testUri); $stream = fopen('data://text/plain,' . $testBody, 'r'); $response = new Response($stream, $testStatus, array(), ['request' => $testRequest]); $this->assertEquals($testBody, $response->getBody()); $this->assertEquals([], $response->getHeader('Test Header')); $this->assertEquals($testStatus, $response->getStatus()); $this->assertEmpty($response->getContentType()); $this->assertEquals($testRequest, $response->getRequest()); }