public function testHeadersHasAndGetWorkProperly() { $headers = new Headers(); $headers->addHeaders(array($f = new Header\GenericHeader('Foo', 'bar'), new Header\GenericHeader('Baz', 'baz'))); $this->assertFalse($headers->has('foobar')); $this->assertTrue($headers->has('foo')); $this->assertTrue($headers->has('Foo')); $this->assertSame($f, $headers->get('foo')); }
/** * Validate the passed mediatype against the appropriate header * * @param string $match * @param HttpHeaders $headers * @return bool */ protected function validateMediaType($match, HttpHeaders $headers) { if (!$headers->has('accept')) { return true; } $accept = $headers->get('accept'); if ($accept->match($match)) { return true; } return false; }
/** * @param Headers $headers * * @return string|null */ private function getBrowseAcceptLanguage(Headers $headers) { if ($headers->has('Accept-Language')) { /** @var AcceptLanguage $acceptLanguageHeader */ $acceptLanguageHeader = $headers->get('Accept-Language'); $locales = $acceptLanguageHeader->getPrioritized(); $languages = $this->config->getAvailableLanguages(); /** @var LanguageFieldValuePart $locale */ foreach ($locales as $locale) { // Loop through all locales, highest priority first if ($browserLang = \Locale::lookup($languages, $locale->getRaw())) { return $browserLang; } } } return null; }
/** * @param Headers $headers * * @return \SplFileInfo */ public function getStreamPath(Headers $headers) { $filename = null; $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(); if (!file_exists($directory)) { mkdir($directory, 0775, true); } if (!$this->filename) { if ($headers->has('content-disposition')) { $field = $headers->get('content-disposition')->getFieldValue(); if (preg_match('`filename\\="(.*)"`', $field, $matches)) { $this->filename = basename($matches[1]); } } if (null === $filename) { $this->filename = uniqid(); } } return new \SplFileInfo($directory . DIRECTORY_SEPARATOR . $this->filename); }
/** * Get the mediatype from a given header * * @param \Zend\Http\Headers $headers * @param string $header * @return string */ protected function getHeaderType($headers, $header) { if (!$headers->has($header)) { return 'application/json'; } $accept = $headers->get($header); $value = $accept->getFieldValue(); $value = explode(';', $value, 2); $accept = array_shift($value); $accept = strtolower(trim($accept)); switch ($accept) { case 'application/json': case 'application/vnd.zfcampus.v1.config+json': return $accept; default: return 'application/json'; } }
/** * @param Headers $headers * @return self */ public function setVary(Headers $headers) { if (!empty($this->cacheConfig['vary']['value']) && (!empty($this->cacheConfig['vary']['override']) || !$headers->has('vary'))) { $vary = new Header\Vary($this->cacheConfig['vary']['value']); $headers->addHeader($vary); } return $this; }