creates header for cookie

@param   array  $cookieValues  cookie values
@return  \stubbles\peer\HeaderList
170691
public function putCookie(array $cookieValues): self
    {
        $cookieValue = '';
        foreach ($cookieValues as $key => $value) {
            $cookieValue .= $key . '=' . urlencode($value) . ';';
        }

        $this->put('Cookie', $cookieValue);
        return $this;
    }
113232
private function parse($headers)
    {
        foreach (preg_split('/\r\n|\r|\n/', $headers) as $i => $line) {
            if ($i === 0) {
                $this->headers['http_code'] = $line;
            } else {
                list($key, $value) = explode(': ', $line);

                if ($key === 'Set-Cookie') {
                    list($textCookie) = explode(';', $value);
                    list($cookieKey, $cookieValue) = explode('=', $textCookie);

                    $this->cookies[$cookieKey] = $cookieValue;
                } else {
                    $this->headers[$key] = $value;
                }
            }
        }
    }
62459
private function setReponseHeaders($contentType = 'text/html', array $cookies = array())
    {
        $powered = Config::getParam('poweredBy', 'PSFS');
        header('X-Powered-By: ' . $powered);
        ResponseHelper::setStatusHeader($this->getStatusCode());
        ResponseHelper::setAuthHeaders($this->isPublicZone());
        ResponseHelper::setCookieHeaders($cookies);
        header('Content-type: ' . $contentType);

    }
542150
public function setCookies(array $cookies)
	{
		$this->cookies = [];
		
		foreach($cookies as $name => $value)
		{
			$this->setCookie($name, $value);
		}
		
		return $this;
	}
1091237
public function addHeader($headerKey, $headerValue)
    {
        if (!is_string($headerKey)) {
            throw new \InvalidArgumentException('Expected headerKey to be a string');
        }

        if (!is_scalar($headerValue)) {
            throw new \InvalidArgumentException('Expected headerValue to be a scalar');
        }

        $oldValue = null;
        if (array_key_exists($headerKey, $this->headers)) {
            $oldValue = $this->headers[$headerKey];
        }

        $this->headers[$headerKey] = $headerValue;

        return $oldValue;
    }
272702
protected function setHeaders(array $headers)
    {
        $this->headerNames = $this->headerValues = [];

        foreach ($headers as $name => $value) {
            if (!is_array($value)) {
                $value = [$value];
            }

            if (in_array(false, array_map('is_string', $value))) {
                throw new InvalidArgumentException('Header value must be string or array of string.');
            }

            $lowerName = strtolower($name);
            $this->headerNames[$lowerName] = $name;
            $this->headerValues[$lowerName] = $value;
        }
    }
38656
public function withCookieParams(array $cookies)
    {
        if ($this->getCookieParams() === $cookies) {
            return $this;
        }

        $newInstance = clone $this;
        $newInstance->setCookieParams($cookies);
        return $newInstance;
    }
586615
private function setCookiesFromHeaders()
    {
        $this->cookies = [];

        $headers = $this->getHeaderAsArray('Cookie');

        foreach ($headers as $line) {
            foreach (explode(';', $line) as $pair) {
                $cookie = BasicCookie::fromHeader($pair);
                $this->cookies[$cookie->getName()] = $cookie;
            }
        }
    }
980499
public function addHeaders(array $headers)
    {

        foreach ($headers as $key => $value) {
            $header = NULL;
            //Handle Array of String based Headers
            if (is_numeric($key) && strpos($value,":") !== FALSE) {
                $arr = explode(":",$value,2);
                if (count($arr)==2){
                    $header = $arr[0];
                    $value = trim($arr[1]);
                }
            } else {
                $header = $key;
            }
            if ($header !== NULL){
                $this->addHeader($header, $value);
            }
        }
        return $this;
    }
805504
protected function buildHeaders($requestHeaders)
    {
        $requestHeaders = $requestHeaders + $this->requestHeaders;
        $resultHeaders = [];

        foreach ($requestHeaders as $headerName => $headerValue) {

            if (is_array($headerValue)) {
                $headerValue = implode(',', $headerValue);
            }

            $resultHeaders[] = ucfirst($headerName) . ': ' . $headerValue;
        }

        return $resultHeaders;
    }
709140
protected static function parseCookies(array $cookieHeader)
    {
        $cookies = [];
        foreach ($cookieHeader as $cookie) {
            if (strpos($cookie, '";"') !== false) {
                $cookie = str_replace('";"', '{__cookie_replace__}', $cookie);
                $parts = preg_split('/\;[ \t]*/', $cookie);
                $parts = str_replace('{__cookie_replace__}', '";"', $parts);
            } else {
                $parts = preg_split('/\;[ \t]*/', $cookie);
            }

            list($name, $value) = explode('=', array_shift($parts), 2);
            $parsed = ['name' => $name, 'value' => urldecode($value)];

            foreach ($parts as $part) {
                if (strpos($part, '=') !== false) {
                    list($key, $value) = explode('=', $part);
                } else {
                    $key = $part;
                    $value = true;
                }

                $key = strtolower($key);
                if ($key === 'httponly') {
                    $key = 'httpOnly';
                }
                if ($key === 'expires') {
                    $key = 'expire';
                    $value = strtotime($value);
                }
                if (!isset($parsed[$key])) {
                    $parsed[$key] = $value;
                }
            }
            $cookies[] = $parsed;
        }

        return $cookies;
    }
148333
public function applyCookies($cookies)
    {
        $values = [];
        foreach ($cookies as $cookie) {
            if ($cookie->matches($this->url())) {
                $values[$cookie->path()] = $cookie->name() . '=' . $cookie->value();
            }
        }

        $keys = array_map('strlen', array_keys($values));
        array_multisort($keys, SORT_DESC, $values);
        $headers = $this->headers();
        if ($values) {
            $headers['Cookie'] = implode('; ', $values);
        } else {
            unset($headers['Cookie']);
        }
        return $this;
    }
96650
public function setCookies($cookies = [])
    {

        $this->cookies = ($cookies instanceof Parameters) ? $cookies : new Parameters("cookies", (array)$cookies);

        return $this;
    }
1183163
private function setHeadersFromCookies()
    {
        $values = [];

        foreach ($this->cookies as $cookie) {
            $values[] = $cookie->toHeader();
        }

        if (!empty($values)) {
            $this->setHeader('Cookie', implode('; ', $values));
        }
    }
674172
public function sendHeaders()
    {
        foreach ($this->_headers as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $v) {
                    header($key.': '.$v, false);
                }
            } else {
                header($key.': '.$value);
            }
        }

        return $this;
    }
1233835
public function setFieldValues(array $fieldValues)
    {
        foreach ($fieldValues as $field => $fieldValue) {
            $this
                ->configuration
                ->setFieldValue(
                    $field,
                    $fieldValue
                );
        }

        return $this;
    }
1294172
private static function serializePHPCookies(string $cookieName, $cookieValue): string
    {
        $cookieParts = [];
        $urlEncodedCookieName = urlencode($cookieName);
        $valueType = gettype($cookieValue);
        switch ($valueType) {
            case 'integer':
            case 'double':
            case 'string':
                $urlEncodedCookieValue = urlencode((string) $cookieValue);
                $cookieParts[] = "$urlEncodedCookieName=$urlEncodedCookieValue";
                break;

            case 'array':
                foreach ($cookieValue as $cookieValueKey => $cookieValueValue) {
                    $cookieParts[] = self::serializePHPCookies($cookieName."[$cookieValueKey]", $cookieValueValue);
                }
                break;

            case 'NULL':
                $cookieParts[] = "$urlEncodedCookieName=";
                break;

            case 'boolean':
                $cookieParts[] = "$urlEncodedCookieName=".((bool) $cookieValue ? '1' : '0');
                break;

            // It's a security risk to serialize an object and send it as a cookie
            case 'object':
                // Intentional fallthrough
            default:
                $cookieParts[] = "$urlEncodedCookieName=".self::UNSUPPORTED_TYPE_VALUE;
                break;
        }

        return implode(';', $cookieParts);
    }