/** * {@inheritdoc} */ public function set($key, $values, $replace = true) { parent::set($key, $values, $replace); if ('cache-control' === strtr(strtolower($key), '_', '-')) { $computed = $this->computeCacheControlValue(); $this->headers['cache-control'] = array($computed); $this->computedCacheControl = $this->parseCacheControl($computed); } }
/** * {@inheritdoc} * * @api */ public function set($key, $values, $replace = true) { parent::set($key, $values, $replace); // ensure the cache-control header has sensible defaults if (in_array(strtr(strtolower($key), '_', '-'), array('cache-control', 'etag', 'last-modified', 'expires'))) { $computed = $this->computeCacheControlValue(); $this->headers['cache-control'] = array($computed); $this->computedCacheControl = $this->parseCacheControl($computed); } }
/** * {@inheritdoc} */ public function set($key, $values, $replace = true) { parent::set($key, $values, $replace); $uniqueKey = str_replace('_', '-', strtolower($key)); $this->headerNames[$uniqueKey] = $key; // ensure the cache-control header has sensible defaults if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) { $computed = $this->computeCacheControlValue(); $this->headers['cache-control'] = array($computed); $this->headerNames['cache-control'] = 'Cache-Control'; $this->computedCacheControl = $this->parseCacheControl($computed); } }
private function parseHeader(HeaderBag $headerBag) { try { $vars = $this->consumeRegexp('/(' . self::TOKEN_HEADER_NAME . '): ?/'); $headerName = $vars[1]; $value = $this->consumeTo("\n"); $this->consume("\n"); while ($this->expects(" ") || $this->expects("\t")) { $value .= $this->consumeTo("\n"); $this->consume("\n"); } $headerBag->set($headerName, $value); } catch (\InvalidArgumentException $e) { return false; } return true; }
/** * {@inheritdoc} */ public function set($key, $values, $replace = true) { $uniqueKey = str_replace('_', '-', strtolower($key)); if ('set-cookie' === $uniqueKey) { if ($replace) { $this->cookies = array(); } foreach ((array) $values as $cookie) { $this->setCookie(Cookie::fromString($cookie)); } $this->headerNames[$uniqueKey] = $key; return; } $this->headerNames[$uniqueKey] = $key; parent::set($key, $values, $replace); // ensure the cache-control header has sensible defaults if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) { $computed = $this->computeCacheControlValue(); $this->headers['cache-control'] = array($computed); $this->headerNames['cache-control'] = 'Cache-Control'; $this->computedCacheControl = $this->parseCacheControl($computed); } }
/** * @covers Smsglobal\RestApiClient\Http\HeaderBag::contains */ public function testContains() { $bag = new HeaderBag(array('foo' => 'bar', 'fuzz' => 'bizz')); $this->assertTrue($bag->contains('foo', 'bar'), '->contains first value'); $this->assertTrue($bag->contains('fuzz', 'bizz'), '->contains second value'); $this->assertFalse($bag->contains('nope', 'nope'), '->contains unknown value'); $this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value'); // Multiple values $bag->set('foo', 'bor', false); $this->assertTrue($bag->contains('foo', 'bar'), '->contains first value'); $this->assertTrue($bag->contains('foo', 'bor'), '->contains second value'); $this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value'); }
/** * @param string $key */ public function set($key, $values, $replace = true) { parent::set($key, $values, $replace); $uniqueKey = strtr(strtolower($key), '_', '-'); $this->headerNames[$uniqueKey] = $key; if (in_array($uniqueKey, ['cache-control', 'etag', 'last-modified', 'expires'])) { $computed = $this->computeCacheControlValue(); $this->headers['cache-control'] = [$computed]; $this->headerNames['cache-control'] = 'Cache-Control'; $this->computedCacheControl = $this->parseCacheControl($computed); } }