src/net/http/HttpRequest.php
public function setHeader($name, $value) {
        if (!is_string($name))                   throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name));
        if (!strlen($name))                      throw new InvalidArgumentException('Invalid argument $name: '.$name);
        if (isset($value) && !is_string($value)) throw new IllegalTypeException('Illegal type of parameter $value: '.gettype($value));

        $name  = trim($name);
        $value = trim($value);

        // drop existing headers of the same name (ignore case)
        $existing = \array_intersect_ukey($this->headers, [$name => '1'], 'strCaseCmp');
        foreach ($existing as $key => $v) {
            unset($this->headers[$key]);
        }

        // set new header if non-empty
        if (!empty($value)) {
            $this->headers[$name] = $value;
        }
        return $this;
    }
public function setHeader($name, $value) {
        if (!is_string($name))                   throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name));
        if (!strlen($name))                      throw new InvalidArgumentException('Invalid argument $name: '.$name);
        if (isset($value) && !is_string($value)) throw new IllegalTypeException('Illegal type of parameter $value: '.gettype($value));

        $name  = trim($name);
        $value = trim($value);

        // drop existing headers of the same name (ignore case)
        $existing = \array_intersect_ukey($this->headers, [$name => '1'], 'strCaseCmp');
        foreach ($existing as $key => $v) {
            unset($this->headers[$key]);
        }

        // set new header if non-empty
        if (!empty($value)) {
            $this->headers[$name] = $value;
        }
        return $this;
    }
public function setHeader ( $ name , $ value ) { if ( ! is_string ( $ name ) ) throw new IllegalTypeException ( 'Illegal type of parameter $name: ' . gettype ( $ name ) ) ; if ( ! strlen ( $ name ) ) throw new InvalidArgumentException ( 'Invalid argument $name: ' . $ name ) ; if ( isset ( $ value ) && ! is_string ( $ value ) ) throw new IllegalTypeException ( 'Illegal type of parameter $value: ' . gettype ( $ value ) ) ; $ name = trim ( $ name ) ; $ value = trim ( $ value ) ; // drop existing headers of the same name (ignore case) $ existing = \ array_intersect_ukey ( $ this -> headers , [ $ name => '1' ] , 'strCaseCmp' ) ; foreach ( $ existing as $ key => $ v ) { unset ( $ this -> headers [ $ key ] ) ; } // set new header if non-empty if ( ! empty ( $ value ) ) { $ this -> headers [ $ name ] = $ value ; } return $ this ; }
Set an HTTP header. This method overwrites an existing header of the same name.

@param  string      $name  - header name
@param  string|null $value - header value (an empty value removes an existing header)

@return $this
Set an HTTP header . This method overwrites an existing header of the same name .