コード例 #1
0
 /**
  * @param HttpSocketTransporter $transporter
  * @param HttpResponse          $response
  * @param null                  $continue
  *                              From Events To Tell Just Continue With Body
  *
  * @return mixed
  */
 function __invoke($transporter = null, $response = null, $continue = null)
 {
     ## Close the connection if requested to do so by the server
     $headers = $response->getHeaders();
     if ($headers->has('connection') && strstr($headers->get('connection')->renderValueLine(), 'close') !== false && $transporter->isConnected() && $continue === false) {
         $transporter->close();
     }
 }
コード例 #2
0
 /**
  * @param HttpSocketTransporter $transporter
  * @param HttpResponse          $response
  * @param Streamable            $stream
  * @param iHttpRequest          $request
  *
  * @return mixed
  */
 function __invoke($transporter = null, $response = null, $stream = null, $request = null)
 {
     $statusCode = $response->getStatCode();
     # Handle 100 and 101 responses
     if ($statusCode == 100 || $statusCode == 101) {
         ## receive data will continue after events
         $transporter->reset();
     }
     # HEAD requests and 204 or 304 stat codes are not expected to have a body
     if ($statusCode == 304 || $statusCode == 204 || $request->getMethod() == HttpRequest::METHOD_HEAD) {
         ## do not continue with body
         return ['continue' => false];
     }
     /*$statusPlugin = new Status(['message_object' => $response]);
       if (!$statusPlugin->isSuccess())
           ## always connection will closed, no need to continue
           return ['continue' => false];*/
 }
コード例 #3
0
 /**
  * @param HttpSocketTransporter $transporter
  * @param iStreamable           $body
  * @param HttpResponse          $response
  * @param Streamable            $stream
  * @param iHttpRequest          $request
  *
  * @return mixed
  */
 function __invoke($transporter = null, $body = null, $response = null, $stream = null, $request = null)
 {
     $headers = $response->getHeaders();
     // Decoding Data:
     if (!$body || !$transporter->optsData()->isAllowDecoding()) {
         ## do not decode body using raw data
         return ['body' => $body];
     }
     if ($headers->has('Content-Encoding') && strstr(strtolower($headers->get('Content-Encoding')->renderValueLine()), 'gzip') !== false) {
         ## Uses PHP's zlib.inflate filter to inflate deflate or gzipped content
         $body->getResource()->appendFilter(new PhpRegisteredFilter('zlib.inflate'), STREAM_FILTER_READ);
         ### skip the first 10 bytes for zlib
         $body = new Streamable\SegmentWrapStream($body, -1, 10);
     }
     if ($headers->has('transfer-encoding') && strstr(strtolower($headers->get('Transfer-Encoding')->renderValueLine()), 'chunked') !== false) {
         $body->getResource()->appendFilter(new DechunkFilter(), STREAM_FILTER_READ);
     }
     return ['body' => $body];
 }