Exemple #1
0
 public function parseHeader($header)
 {
     $request = new Request();
     $header = new Text($header);
     $lines = $header->lines();
     $first = array_shift($lines);
     $parts = explode(' ', $first);
     foreach ($parts as $index => $value) {
         switch ($index) {
             case 0:
                 $request->setMethod($value);
                 break;
             case 1:
                 $path = parse_url($value, PHP_URL_PATH);
                 $query = parse_url($value, PHP_URL_QUERY);
                 $request->setUri($path);
                 $request->setPath($path);
                 $request->setQueryString($query);
                 break;
             case 2:
                 list($protocol, $version) = explode('/', trim($value));
                 $request->setProtocol($protocol);
                 $request->setProtocolVersion($version);
                 break;
         }
     }
     foreach ($lines as $line) {
         if (!$line->trim()->isEmpty()) {
             list($name, $value) = explode(':', $line, 2);
             $request->setHeader(trim($name), trim($value));
         }
     }
     return $request;
 }
Exemple #2
0
 /**
  * @param        $output
  * @param string $errorOutput
  *
  * @return Response
  */
 protected function parseOutput($output, $errorOutput = '')
 {
     $response = new Response();
     list($header, $body) = explode("\r\n\r\n", $output, 2);
     $response->setBody($body);
     $response->setError($errorOutput);
     $header = new Text($header);
     $cookies = [];
     foreach ($header->lines() as $line) {
         list($name, $value) = explode(':', $line, 2);
         if ('Set-Cookie' == $name) {
             $cookies[] = trim($value);
         } else {
             $response->setHeader(trim($name), trim($value));
         }
     }
     if (count($cookies)) {
         $response->setHeader('Set-Cookie', $cookies);
     }
     return $response;
 }
Exemple #3
0
 public function testSave()
 {
     $this->expectOutputString('foo');
     $text = new Text('foo');
     $text->save('php://output');
 }