Esempio n. 1
0
 /**
  * @param $data
  */
 public function parseHead($data)
 {
     $this->buffer .= $data;
     if (false !== strpos($this->buffer, "\r\n\r\n")) {
         list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
         // Reset buffer useless now
         $this->buffer = "";
         // extract headers
         $psrRequest = \GuzzleHttp\Psr7\parse_request($headers);
         $this->request->onHead($psrRequest);
         $encoding = $this->request->getHeader("Transfer-Encoding");
         if (in_array($this->request->getMethod(), ['GET', 'HEAD'])) {
             $this->notifyCompleted();
             return;
         }
         switch ($encoding) {
             case "chunked":
                 $this->parserCallable = [$this, 'parseChunk'];
                 break;
                 // TODO multipart
             // TODO multipart
             default:
                 $this->parserCallable = [$this, 'parseContentLength'];
                 if ($length = $this->request->getHeader("Content-Length")) {
                     $this->contentLength = intval($length);
                 }
         }
         // Parse rest of body
         $this->parse($bodyBuffer);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function __invoke(StreamInterface $stream)
 {
     $request = \GuzzleHttp\Psr7\parse_request($stream->getContents());
     $response = $this->run($request);
     if ($this->getAssertionCallback()) {
         call_user_func($this->getAssertionCallback(), $request);
     }
     return \GuzzleHttp\Psr7\stream_for(\GuzzleHttp\Psr7\str($response));
 }
Esempio n. 3
0
 public function parseHeaders($data)
 {
     try {
         $parsed = \GuzzleHttp\Psr7\parse_request($data);
     } catch (\InvalidArgumentException $e) {
         return null;
     }
     return new Request($parsed->getMethod(), $parsed->getUri(), $parsed->getUri()->getQuery(), $parsed->getProtocolVersion(), $parsed->getHeaders());
 }