Example #1
0
 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 = $this->parseHeaders($headers . "\r\n\r\n");
         if ($this->request->expectsContinue()) {
             $this->emit('expects_continue');
         }
     }
     // 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()) {
         $this->parseBody(substr($this->buffer, 0, $this->length));
         $this->finishParsing();
         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;
     }
 }
Example #2
0
 /** @test */
 public function expectsContinueShouldBeTrueIfContinueExpected()
 {
     $headers = array('Expect' => '100-continue');
     $request = new Request('GET', '/', array(), '1.1', $headers);
     $this->assertTrue($request->expectsContinue());
 }