src/Headers.php
protected function _set($values, $prepend = false)
    {
        $header = $this->_classes['header'];
        $headers = is_string($values) ? explode("\n", $values) : $values;
        $headers = $headers ? $headers : [];

        foreach ($headers as $key => $value) {
            if (!is_numeric($key)) {
                if ($value instanceof $header) {
                    $value->name($key);
                } elseif (is_array($value)) {
                    $value = "{$key}: " . join(', ', $value);
                } else {
                    $value = "{$key}: {$value}";
                }
            }

            if (is_string($value)) {
                $value = trim($value);
            }

            if (!$value) {
                continue;
            }

            if ($value instanceof $header) {
                $parsed = $value;
            } elseif (!$parsed = $header::parse($value)) {
                throw new NetException("Invalid header: `'{$value}'`.");
            }

            $name = strtolower($parsed->name());
            if (!$name) {
                throw new Exception("Error, invalid header name, can't be empty.");
            }

            if ($name === 'set-cookie' && isset($this->_data[$name])) {
                $previsous = $this->_data[$name];
                $previsous[] = $parsed->value();
                $parsed = $previsous;
            }
            if ($prepend) {
                $this->_data = [$name => $parsed] + $this->_data;
            } else {
                $this->_data = array_merge($this->_data, [$name => $parsed]);
            }
        }
        return $this;
    }
protected function _set($values, $prepend = false)
    {
        $header = $this->_classes['header'];
        $headers = is_string($values) ? explode("\n", $values) : $values;
        $headers = $headers ? $headers : [];

        foreach ($headers as $key => $value) {
            if (!is_numeric($key)) {
                if ($value instanceof $header) {
                    $value->name($key);
                } elseif (is_array($value)) {
                    $value = "{$key}: " . join(', ', $value);
                } else {
                    $value = "{$key}: {$value}";
                }
            }

            if (is_string($value)) {
                $value = trim($value);
            }

            if (!$value) {
                continue;
            }

            if ($value instanceof $header) {
                $parsed = $value;
            } elseif (!$parsed = $header::parse($value)) {
                throw new NetException("Invalid header: `'{$value}'`.");
            }

            $name = strtolower($parsed->name());
            if (!$name) {
                throw new Exception("Error, invalid header name, can't be empty.");
            }

            if ($name === 'set-cookie' && isset($this->_data[$name])) {
                $previsous = $this->_data[$name];
                $previsous[] = $parsed->value();
                $parsed = $previsous;
            }
            if ($prepend) {
                $this->_data = [$name => $parsed] + $this->_data;
            } else {
                $this->_data = array_merge($this->_data, [$name => $parsed]);
            }
        }
        return $this;
    }
protected function _set ( $ values , $ prepend = false ) { $ header = $ this -> _classes [ 'header' ] ; $ headers = is_string ( $ values ) ? explode ( "\n" , $ values ) : $ values ; $ headers = $ headers ? $ headers : [ ] ; foreach ( $ headers as $ key => $ value ) { if ( ! is_numeric ( $ key ) ) { if ( $ value instanceof $ header ) { $ value -> name ( $ key ) ; } elseif ( is_array ( $ value ) ) { $ value = "{$key}: " . join ( ', ' , $ value ) ; } else { $ value = "{$key}: {$value}" ; } } if ( is_string ( $ value ) ) { $ value = trim ( $ value ) ; } if ( ! $ value ) { continue ; } if ( $ value instanceof $ header ) { $ parsed = $ value ; } elseif ( ! $ parsed = $ header :: parse ( $ value ) ) { throw new NetException ( "Invalid header: `'{$value}'`." ) ; } $ name = strtolower ( $ parsed -> name ( ) ) ; if ( ! $ name ) { throw new Exception ( "Error, invalid header name, can't be empty." ) ; } if ( $ name === 'set-cookie' && isset ( $ this -> _data [ $ name ] ) ) { $ previsous = $ this -> _data [ $ name ] ; $ previsous [ ] = $ parsed -> value ( ) ; $ parsed = $ previsous ; } if ( $ prepend ) { $ this -> _data = [ $ name => $ parsed ] + $ this -> _data ; } else { $ this -> _data = array_merge ( $ this -> _data , [ $ name => $ parsed ] ) ; } } return $ this ; }
Sets one or some plain string headers.

@param  string|array $headers A header string or an array of headers.
@param  boolean      $prepend If true, prepend headers to the beginning.
@return self
Sets one or some plain string headers .