51 $status = array_shift($headers);
54 foreach ($headers as $headerLine) {
55 $headerLine = trim($headerLine);
56 if (
'' === $headerLine) {
78 if (!(is_string($headers)
79 || (is_object($headers) && method_exists($headers,
'__toString')))
81 throw new \InvalidArgumentException(
83 '%s expects parameter 1 to be a string, %s given',
85 is_object($headers) ? get_class($headers) : gettype($headers)
106 $parts = explode(
' ', $statusLine, 3);
107 if (count($parts) < 2 || 0 !== strpos(strtolower($parts[0]),
'http/')) {
108 throw new \InvalidArgumentException(
109 sprintf(
'"%s" is not a valid HTTP status line', $statusLine)
113 $reasonPhrase = count($parts) > 2 ? $parts[2] :
'';
114 $this->response = $this->response
115 ->withStatus((
int) $parts[1], $reasonPhrase)
116 ->withProtocolVersion(substr($parts[0], 5));
132 $parts = explode(
':', $headerLine, 2);
133 if (2 !== count($parts)) {
134 throw new \InvalidArgumentException(
135 sprintf(
'"%s" is not a valid HTTP header line', $headerLine)
138 $name = trim($parts[0]);
139 $value = trim($parts[1]);
140 if ($this->response->hasHeader($name)) {
141 $this->response = $this->response->withAddedHeader($name, $value);
143 $this->response = $this->response->withHeader($name, $value);