Beispiel #1
0
 public function parseHeaders($data)
 {
     $psrRequest = gPsr\parse_request($data);
     $parsedQuery = [];
     $queryString = $psrRequest->getUri()->getQuery();
     if ($queryString) {
         parse_str($queryString, $parsedQuery);
     }
     $headers = array_map(function ($val) {
         if (1 === count($val)) {
             $val = $val[0];
         }
         return $val;
     }, $psrRequest->getHeaders());
     return new Request($psrRequest->getMethod(), $psrRequest->getUri(), $parsedQuery, $psrRequest->getProtocolVersion(), $headers);
 }
 public function feed($data)
 {
     $this->buffer .= $data;
     if (!$this->request && false !== strpos($this->buffer, "\r\n\r\n")) {
         // Extract the header from the buffer
         // in case the content isn't complete
         list($headers, $this->buffer) = explode("\r\n\r\n", $this->buffer, 2);
         // Fail before parsing if the
         if (strlen($headers) > $this->maxSize) {
             $this->headerSizeExceeded();
             return;
         }
         $this->request = gPsr\parse_request($headers . "\r\n\r\n");
     }
     // if there is a request (meaning the headers are parsed) and
     // we have the right content size, we can finish the parsing
     if ($this->request && $this->isRequestComplete()) {
         $body = substr($this->buffer, 0, $this->length);
         // create a stream for the body.
         $stream = new BufferedStream();
         $stream->write($body);
         // add stream to the request.
         $this->request = $this->request->withBody($stream);
         // create server request object
         $this->request = new ServerRequest($this->request);
         // todo this should really belong in the header parsing.  clean this up.
         $parsedQuery = [];
         $queryString = $this->request->getUri()->getQuery();
         if ($queryString) {
             parse_str($queryString, $parsedQuery);
             if (!empty($parsedQuery)) {
                 $this->request = $this->request->withQueryParams($parsedQuery);
             }
         }
         // add server request information to the request object.
         $this->request = $this->parseBody($body, $this->request);
         $this->emit('headers', array($this->request));
         $this->removeAllListeners();
         $this->request = null;
         return;
     }
     // fail if the header hasn't finished but it is already too large
     if (!$this->request && strlen($this->buffer) > $this->maxSize) {
         $this->headerSizeExceeded();
         return;
     }
 }
Beispiel #3
0
 public function parseRequest($data)
 {
     list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
     $psrRequest = g7\parse_request($headers);
     $parsedQuery = [];
     $queryString = $psrRequest->getUri()->getQuery();
     if ($queryString) {
         parse_str($queryString, $parsedQuery);
     }
     $headers = $psrRequest->getHeaders();
     array_walk($headers, function (&$val) {
         if (1 === count($val)) {
             $val = $val[0];
         }
     });
     $request = new Request($psrRequest->getMethod(), $psrRequest->getUri()->getPath(), $parsedQuery, $psrRequest->getProtocolVersion(), $headers);
     return array($request, $bodyBuffer);
 }
Beispiel #4
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testValidatesRequestMessages()
 {
     Psr7\parse_request("HTTP/1.1 200 OK\r\n\r\n");
 }
 public function setUp()
 {
     $request = parse_request(file_get_contents(__DIR__ . '/../examples/gitlab-push-event.req'));
     $provider = new GitLabProvider();
     $this->pushEvent = $provider->create($request);
 }