You are here

public function MessageTrait::withHeader in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-diactoros/src/MessageTrait.php \Zend\Diactoros\MessageTrait::withHeader()
  2. 8 vendor/guzzlehttp/psr7/src/MessageTrait.php \GuzzleHttp\Psr7\MessageTrait::withHeader()
Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/psr7/src/MessageTrait.php \GuzzleHttp\Psr7\MessageTrait::withHeader()
2 calls to MessageTrait::withHeader()
MessageTrait::withAddedHeader in vendor/guzzlehttp/psr7/src/MessageTrait.php
Request::withHeader in vendor/guzzlehttp/psr7/src/Request.php
Return an instance with the provided value replacing the specified header.

File

vendor/guzzlehttp/psr7/src/MessageTrait.php, line 60

Class

MessageTrait
Trait implementing functionality common to requests and responses.

Namespace

GuzzleHttp\Psr7

Code

public function withHeader($header, $value) {
  $new = clone $this;
  $header = trim($header);
  $name = strtolower($header);
  if (!is_array($value)) {
    $new->headers[$name] = [
      trim($value),
    ];
  }
  else {
    $new->headers[$name] = $value;
    foreach ($new->headers[$name] as &$v) {
      $v = trim($v);
    }
  }

  // Remove the header lines.
  foreach (array_keys($new->headerLines) as $key) {
    if (strtolower($key) === $name) {
      unset($new->headerLines[$key]);
    }
  }

  // Add the header line.
  $new->headerLines[$header] = $new->headers[$name];
  return $new;
}