Esempio n. 1
0
 protected function streamWriter(WritableStream $stream, Channel $channel, callable $transform = null) : \Generator
 {
     $len = 0;
     try {
         while (null !== ($chunk = (yield $channel->receive()))) {
             $len += (yield $stream->write($transform ? $transform($chunk) : $chunk));
         }
         return $len;
     } catch (\Throwable $e) {
         $channel->close($e);
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * Create the input stream being used to read decoded body data from the remote peer.
  * 
  * @return ReadableStream
  */
 protected function createInputStream() : \Generator
 {
     if ($this->expectContinue) {
         (yield $this->expectContinue->write("HTTP/1.1 100 Continue\r\n"));
     }
     if ($this->chunked) {
         $stream = new ChunkDecodedStream($this->stream, $this->cascadeClose);
     } elseif ($this->length > 0) {
         $stream = new LimitStream($this->stream, $this->length, $this->cascadeClose);
     } else {
         if ($this->cascadeClose) {
             $this->stream->close();
         }
         return new ReadableMemoryStream();
     }
     switch ($this->compression) {
         case self::COMPRESSION_GZIP:
             return new ReadableInflateStream($stream, \ZLIB_ENCODING_GZIP);
         case self::COMPRESSION_DEFLATE:
             return new ReadableInflateStream($stream, \ZLIB_ENCODING_DEFLATE);
     }
     return $stream;
 }