lithium\net\http\Response::_parseMessage()

protected method

Accepts an entire HTTP message including headers and body, and parses it into a message body an array of headers, and the HTTP status.

Parameters

  • string $body

    The full body of the message.

Returns

After

parsing out other message components, returns just the message body.

Source

	protected function _parseMessage($body) {
		if (!($parts = explode("\r\n\r\n", $body, 2)) || count($parts) === 1) {
			return trim($body);
		}
		list($headers, $body) = $parts;
		$headers = str_replace("\r", "", explode("\n", $headers));

		if (array_filter($headers) === []) {
			return trim($body);
		}
		preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)(?:\s+(.*))?/i', array_shift($headers), $match);
		$this->headers($headers, false);

		if (!$match) {
			return trim($body);
		}
		list($line, $this->version, $code) = $match;
		if (isset($this->_statuses[$code])) {
			$message = $this->_statuses[$code];
		}
		if (isset($match[3])) {
			$message = $match[3];
		}
		$this->status = compact('code', 'message') + $this->status;
		$this->protocol = "HTTP/{$this->version}";
		return $body;
	}