コード例 #1
0
ファイル: Response.php プロジェクト: amouhzi/http-message
 /**
  * Ensure header names and values are valid.
  *
  * @param array $headers
  * @throws InvalidArgumentException
  */
 private function assertHeaders(array $headers)
 {
     foreach ($headers as $name => $headerValues) {
         HeaderSecurity::assertValidName($name);
         array_walk($headerValues, __NAMESPACE__ . '\\HeaderSecurity::assertValid');
     }
 }
コード例 #2
0
 /**
  * Set the header appended with the given value.
  *
  * Existing values for the specified header will be maintained. The new
  * value(s) will be appended to the existing list. If the header did not
  * exist previously, it will be added.
  *
  * @param string $header Case-insensitive header field name to add.
  * @param string|string[] $value Header value(s).
  * @return self
  * @throws \InvalidArgumentException for invalid header names or values.
  */
 public function appendHeader($header, $value)
 {
     if (is_string($value)) {
         $value = [$value];
     }
     if (!is_array($value) || !$this->arrayContainsOnlyStrings($value)) {
         throw new InvalidArgumentException('Invalid header value; must be a string or array of strings');
     }
     HeaderSecurity::assertValidName($header);
     self::assertValidHeaderValue($value);
     if (!$this->hasHeader($header)) {
         return $this->setHeader($header, $value);
     }
     $normalized = strtolower($header);
     $header = $this->headerNames[$normalized];
     $this->headers[$header] = array_merge($this->headers[$header], $value);
     return $this;
 }