Esempio n. 1
0
 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');
         }
     }
 }
Esempio n. 2
0
 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');
         }
     }
 }
Esempio n. 3
0
 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');
         }
     }
 }
Esempio n. 4
0
 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 . '"');
         }
     }
 }
Esempio n. 5
0
 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');
                 }
             }
         }
     }
 }