setBody(null); foreach ($headers as $i => $header) { if ('' == trim($header)) { unset($headers[$i]); $this->setBody( trim( implode("\r\n", array_splice($headers, $i)) ) ); break; } } if (0 === preg_match('#^([^\s]+)\s+([^\s]+)\s+HTTP/(1\.(?:0|1))$#i', $http, $matches)) { throw new Exception( 'HTTP headers are not well-formed: %s', 0, $http ); } switch ($method = strtolower($matches[1])) { case self::METHOD_CONNECT: case self::METHOD_DELETE: case self::METHOD_GET: case self::METHOD_HEAD: case self::METHOD_OPTIONS: case self::METHOD_PATCH: case self::METHOD_POST: case self::METHOD_PUT: case self::METHOD_TRACE: $this->_method = $method; break; default: $this->_method = self::METHOD_EXTENDED; } $this->setUrl($matches[2]); $this->setHttpVersion((float) $matches[3]); $this->_parse($headers); return; } /** * Set request method. * * @param string $method Method (please, see self::METHOD_* * constants). * @return string */ public function setMethod($method) { $old = $this->_method; $this->_method = $method; return $old; } /** * Get request method. * * @return string */ public function getMethod() { return $this->_method; } /** * Set request URL. * * @param string $url URL. * @return string */ public function setUrl($url) { $old = $this->_url; $this->_url = $url; return $old; } /** * Get request URL. * * @return string */ public function getUrl() { return $this->_url; } /** * Dump (parse^-1). * * @return string */ public function __toString() { return strtoupper($this->getMethod()) . ' ' . $this->getUrl() . ' ' . 'HTTP/' . $this->getHttpVersion() . CRLF . parent::__toString() . CRLF; } }