Get body with headers.

@param MessageInterface $stream

@return string
177826
public function getBodyWithHeaders(MessageInterface $stream)
    {
        $result = sprintf(
            '%s%s%s',
            $this->getString($stream->getHeaders()),
            PHP_EOL,
            $stream->getBody()->getContents()
        );

        return $result;
    }
1233337
public static function getHeadersFromBrowserResponse(MessageInterface $browserResponse)
    {
        $newheaders = array();
        $headers = $browserResponse->getHeaders();
        foreach($headers as $header)
        {
            $pos = stripos($header, ":");
            if(is_int($pos))
            {
                $newheaders[substr($header, 0, $pos)] = substr($header, $pos + 1);
            }
        }
        return $newheaders;
    }
19921
public static function stream($body = null): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_resource($body)) {
            return new Stream($body);
        }

        $resource = \fopen('php://temp', 'rw+b');
        $stream = new Stream($resource);
        if ($body) {
            $stream->write($body);
        }

        return $stream;
    }
375439
public static function body($message)
    {
        if (!isset($message['body'])) {
            return null;
        }

        if ($message['body'] instanceof StreamInterface) {
            return (string) $message['body'];
        }

        switch (gettype($message['body'])) {
            case 'string':
                return $message['body'];
            case 'resource':
                return stream_get_contents($message['body']);
            case 'object':
                if ($message['body'] instanceof \Iterator) {
                    return implode('', iterator_to_array($message['body']));
                } elseif (method_exists($message['body'], '__toString')) {
                    return (string) $message['body'];
                }
            default:
                throw new \InvalidArgumentException('Invalid request body: '
                    . self::describeType($message['body']));
        }
    }
160546
public function hasStream($stream)
    {
        $isInputStream = $stream == $this->getInputStream();
        $isOutputStream = $stream == $this->getOutputStream();
        $isErrStream = $stream == $this->getErrorStream();

        return $isInputStream || $isOutputStream || $isErrStream;
    }
111576
public static function getMessageSize(MessageInterface $message, $default = null)
    {
        $bodySize = $message->getBody()->getSize();

        if (null === $bodySize) {
            return $default;
        }

        $firstLine = '';

        if ($message instanceof ServerRequestInterface) {
            $firstLine = self::getRequestLine($message);
        } elseif ($message instanceof ResponseInterface) {
            $firstLine = self::getResponseLine($message);
        }

        $headers = [];

        foreach ($message->getHeaders() as $header => $values) {
            foreach ($values as $value) {
                $headers[] = sprintf('%s: %s', $header, $value);
            }
        }

        $headersSize = strlen(implode("\r\n", $headers));

        return strlen($firstLine) + 2 + $headersSize + 4 + $bodySize;
    }
1359875
protected function handleBody($body)
    {
        if (is_string($body)) {
            $stream = new Stream('php://temp', 'wb+');
            $stream->write($body);
            $stream->rewind();

            $body = $stream;
        }

        if (!$body instanceof StreamInterface) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Invalid body content type %s, please provide string or StreamInterface',
                    gettype($body)
                )
            );
        }

        return $body;
    }
886588
private function parseImportList(Stream $stream)
    {
        $list = [];

        do {
            $resource = $this->parseIdentifier($stream);

            if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
                $stream->expects(Token::TYPE_KEYWORD, 'as');

                $alias = $this->parseIdentifier($stream);
            } else {
                $alias = $resource;
            }

            $list[$resource] = $alias;
        } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));

        return $list;
    }
932054
public static function create($body = ''): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_string($body)) {
            $resource = \fopen('php://temp', 'rw+');
            \fwrite($resource, $body);
            $body = $resource;
        }

        if (\is_resource($body)) {
            $new = new self();
            $new->stream = $body;
            $meta = \stream_get_meta_data($new->stream);
            $new->seekable = $meta['seekable'];
            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
            $new->uri = $new->getMetadata('uri');

            return $new;
        }

        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
    }
1318072
public function body($body)
    {
        if ($body instanceof ReadableStreamInterface) {
            return new ReadableBodyStream($body);
        }

        return \RingCentral\Psr7\stream_for($body);
    }
252178
protected static function jsonParser(StreamInterface $stream): array
	{
		$json = \trim((string) $stream);
		if ($json === '') {
			return [];
		}

		$data = \json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
		if (\json_last_error() !== JSON_ERROR_NONE) {
			throw new \DomainException(\json_last_error_msg());
		}

		return ['body' => $data ?: []];
	}
467172
public function fromStream(FilesystemStreamInterface $stream)
    {
        $mimetype = null;

        if (static::isSupported())
        {
            if ($finfo = new \finfo(FILEINFO_MIME_TYPE, $this->getConfig()->magic_file))
            {
                if ($path = $stream->getPath()) {
                    $mimetype = $finfo->file($path);
                } else $mimetype = $finfo->buffer($stream->toString());
            }
        }

        return $mimetype;
    }
488077
public function withBody(StreamInterface $body)
    {
        $new = $this->psrRequest->withBody($body);
        return new self($new, $this->originalRequest);
    }
1163020
public function getBodyPart($id, $stream = false)
    {
        return $this->_msgText(
            $stream,
            isset($this->_data[Horde_Imap_Client::FETCH_BODYPART][$id])
                ? $this->_data[Horde_Imap_Client::FETCH_BODYPART][$id]['t']
                : null
        );
    }
340026
public static function getResource(StreamInterface $stream)
    {
        self::register();

        if ($stream->isReadable()) {
            $mode = $stream->isWritable() ? 'r+' : 'r';
        } elseif ($stream->isWritable()) {
            $mode = 'w';
        } else {
            throw new \InvalidArgumentException('The stream must be readable, '
                .'writable, or both.');
        }

        return fopen('phmessage://stream', $mode, null, stream_context_create([
            'phmessage' => ['stream' => $stream],
        ]));
    }
795184
public function receive(ProtoStream $stream = null)
    {
        $socket = $stream ?: $this->getStream();
        $length = $this->receiveLengthHeader($socket);
        $code   = $this->receiveMessageCode($socket);
        $body   = ($length > 1)
            ? $this->receiveMessageBody($socket, $length - 1)
            : null;

        return [$code, $body];
    }
1004365
protected function read(StreamInterface $stream)
    {
        $partBuilder = $this->partBuilderFactory->newPartBuilder(
            $this->partFactoryService->getMessageFactory()
        );
        // the remaining parts use a resource handle for better performance...
        // it seems fgets does much better than Psr7\readline (not specifically
        // measured, but difference in running tests is big)
        $this->readPart(StreamWrapper::getResource($stream), $partBuilder);
        return $partBuilder;
    }