public function testParsesResponsesWithMissingReasonPhrase()
 {
     $parser = new MessageParser();
     $parts = $parser->parseResponse("HTTP/1.1 200\r\n\r\n");
     $this->assertEquals('200', $parts['code']);
     $this->assertEquals('', $parts['reason_phrase']);
     $this->assertEquals('HTTP', $parts['protocol']);
     $this->assertEquals('1.1', $parts['protocol_version']);
 }
예제 #2
0
 /**
  * Create a request or response object from an HTTP message string
  *
  * @param string $message Message to parse
  *
  * @return RequestInterface|ResponseInterface
  * @throws \InvalidArgumentException if unable to parse a message
  */
 public function fromMessage($message)
 {
     static $parser;
     if (!$parser) {
         $parser = new MessageParser();
     }
     // Parse a response
     if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
         $data = $parser->parseResponse($message);
         return $this->createResponse($data['code'], $data['headers'], $data['body'] === '' ? null : $data['body'], $data);
     }
     // Parse a request
     if (!($data = $parser->parseRequest($message))) {
         throw new \InvalidArgumentException('Unable to parse request');
     }
     return $this->createRequest($data['method'], Url::buildUrl($data['request_url']), ['headers' => $data['headers'], 'body' => $data['body'] === '' ? null : $data['body'], 'config' => ['protocol_version' => $data['protocol_version']]]);
 }