Deserialize a message header from the input stream.

A message header is structured as:
- NAME String
- MUST UNDERSTAND Boolean
- LENGTH Int
- DATA Object

@return Zend_Amf_Value_MessageHeader
426280
public function readHeader()
    {
        $name     = $this->_inputStream->readUTF();
        $mustRead = (bool)$this->_inputStream->readByte();
        $length   = $this->_inputStream->readLong();

        try {
            $data = $this->_deserializer->readTypeMarker();
        } catch (Exception $e) {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Unable to parse ' . $name . ' header data: ' . $e->getMessage() . ' '. $e->getLine(), 0, $e);
        }

        $header = new Zend_Amf_Value_MessageHeader($name, $mustRead, $data, $length);
        return $header;
    }
1257130
public function deserialize(): object
    {
        $this->buffer->position($this->assetOffset / 2);

        $usernameLength = $this->buffer->readUInt8();

        $this->transaction->asset = [
            'delegate' => [
                'username' => $this->buffer->position($this->assetOffset + 2)->readHexBytes($usernameLength * 2),
            ],
        ];

        return $this->parseSignatures($this->assetOffset + ($usernameLength + 1) * 2);
    }
159744
public function toString()
    {
        $headers = $this->toArray();
        $content = '';

        //Serialise the headers to a string
        foreach ($headers as $name => $value) {
            $content .= sprintf("%s %s\r\n", $name.':', $value);
        }

        return $content;
    }
490705
public function getContentIterator()
    {
        // Initializing output array
        $output = new \ArrayIterator();

        // Getting total number of messages
        $maxMessage = $this->storage->countMessages();

        for($i=1; $i<=$maxMessage; $i++) {
            // Getting the message object
            $message = $this->storage->getMessage($i);

            if ($message instanceof \Zend\Mail\Storage\Message) {
                // Wrapping the result object into an appropriate ResourceInterface instance
                try {
                    $popMessage = new PopMessage();
                    $popMessage->init($this->getName(), $i, $message);
                } catch (\Exception $e) {
                    throw new Exception\SourceGetContentException(
                        sprintf(
                            'Error while getting the content for the resource unique id \'%s\'. Exception is: \'%s\'.',
                            $i,
                            $e->getMessage()
                        )
                    );
                }

                // Adding the wrapping object to the result iterator
                $output->append($popMessage);
            }
        }

        // Returning the result iterator
        return $output;
    }
258856
private function readBody(): self
    {
        if (null !== $this->body) {
            return $this;
        }

        if ($this->headers->get('Transfer-Encoding') === 'chunked') {
            $this->body = $this->readChunked();
        } else {
            $this->body = $this->readDefault((int) $this->headers->get('Content-Length', 4096));
        }

        return $this;
    }
712365
public function getEncodedStream()
    {
        if (!$this->_isStream) {
            // require_once 'Zend/Mime/Exception.php';
            throw new Zend_Mime_Exception('Attempt to get a stream from a string part');
        }

        //stream_filter_remove(); // ??? is that right?
        switch ($this->encoding) {
            case Zend_Mime::ENCODING_QUOTEDPRINTABLE:
                $filter = stream_filter_append(
                    $this->_content,
                    'convert.quoted-printable-encode',
                    STREAM_FILTER_READ,
                    array(
                        'line-length'      => 76,
                        'line-break-chars' => Zend_Mime::LINEEND
                    )
                );
                if (!is_resource($filter)) {
                    // require_once 'Zend/Mime/Exception.php';
                    throw new Zend_Mime_Exception('Failed to append quoted-printable filter');
                }
                break;
            case Zend_Mime::ENCODING_BASE64:
                $filter = stream_filter_append(
                    $this->_content,
                    'convert.base64-encode',
                    STREAM_FILTER_READ,
                    array(
                        'line-length'      => 76,
                        'line-break-chars' => Zend_Mime::LINEEND
                    )
                );
                if (!is_resource($filter)) {
                    // require_once 'Zend/Mime/Exception.php';
                    throw new Zend_Mime_Exception('Failed to append base64 filter');
                }
                break;
            default:
        }
        return $this->_content;
    }
825375
protected function getAmzHeaders(): string
    {
        $amzHeaders = [];
        $headers = $this->request->getHeaders();
        foreach ($headers as $headerName => $headerValue) {
            if (0 === strpos(strtolower($headerName), 'x-amz-')) {
                $amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0])."\n";
            }
        }
        ksort($amzHeaders);

        $headerStr = '';
        foreach ($amzHeaders as $h => $v) {
            $headerStr .= $h.':'.$v;
        }

        return $headerStr;
    }
1316608
public function readBytes($length)
    {
        if (($length + $this->_needle) > $this->_streamLength) {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
        }
        $bytes = substr($this->_stream, $this->_needle, $length);
        $this->_needle+= $length;
        return $bytes;
    }
1370046
protected function _encodeHeader($value)
    {
        if (Zend_Mime::isPrintable($value) === false) {
            if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) {
                $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            } else {
                $value = Zend_Mime::encodeBase64Header($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            }
        }

        return $value;
    }
41857
public function getFrom()
    {
        if ($this->from) {
            return $this->from;
        }

        if ($this->alphaNumSender && strlen($this->alphaNumSender) > 0) {
            return $this->alphaNumSender;
        }
    }
712263
private function getMessageHeader(AMQPMessage $message, $header)
    {
        $headers = $message->has('application_headers') ? $message->get('application_headers') : [];

        return array_key_exists($header, $headers) ? $headers[$header] : null;
    }
956057
private function readHeader(): self
    {
        if (null !== $this->statusLine) {
            return $this;
        }

        do {
            $this->parseStatusLine($this->socket->readLine());
            $headers = '';
            $line    = '';
            while (!$this->socket->eof() && Http::END_OF_LINE !== $line) {
                $line     = $this->socket->readLine() . Http::END_OF_LINE;
                $headers .= $line;
            }

            $this->headers->append($headers);
        } while ($this->requireContinue());
        return $this;
    }
1219407
public function deserialize(): object
    {
        $this->buffer->position($this->assetOffset / 2);

        $this->transaction->amount = $this->buffer->readUInt64();
        $this->transaction->expiration = $this->buffer->readUInt32();
        $this->transaction->recipientId = Base58::encodeCheck(new Buffer(hex2bin($this->buffer->readHex(21))));

        return $this->parseSignatures($this->assetOffset + (8 + 4 + 21) * 2);
    }
1120976
public function readAmf3TypeMarker()
    {
        require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
        $deserializer = new Zend_Amf_Parse_Amf3_Deserializer($this->_stream);
        $this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
        return $deserializer->readTypeMarker();
    }
432526
public function deserialize($header)
    {
        if (preg_match(self::CONTEXT_HEADER_FORMAT, $header, $matches)) {
            if ($matches[1] == "00") {
                return $this->deserializeVersion0($matches[2]);
            } else {
                trigger_error("Unrecognized SpanContext header version: " . $matches[1], E_USER_WARNING);
            }
        }
        return new SpanContext();
    }
667231
public function readMessage(Zend_Amf_Parse_InputStream $stream)
    {
        $clientVersion = $stream->readUnsignedShort();
        if (($clientVersion != Zend_Amf_Constants::AMF0_OBJECT_ENCODING)
            && ($clientVersion != Zend_Amf_Constants::AMF3_OBJECT_ENCODING)
            && ($clientVersion != Zend_Amf_Constants::FMS_OBJECT_ENCODING)
        ) {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Unknown Player Version ' . $clientVersion);
        }

        $this->_bodies  = array();
        $this->_headers = array();
        $headerCount    = $stream->readInt();

        // Iterate through the AMF envelope header
        while ($headerCount--) {
            $this->_headers[] = $this->readHeader();
        }

        // Iterate through the AMF envelope body
        $bodyCount = $stream->readInt();
        while ($bodyCount--) {
            $this->_bodies[] = $this->readBody();
        }

        return $this;
    }
928761
public static function fromString($headerLine, $bypassHeaderFieldName = false)
    {
        list($name, $value) = explode(': ', $headerLine, 2);

        // check to ensure proper header type for this factory
        if (strtolower($name) !== 'set-cookie') {
            throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid header line for Set-Cookie string: "' . $name . '"');
        }

        $multipleHeaders = preg_split('#(?<!Sun|Mon|Tue|Wed|Thu|Fri|Sat),\s*#', $value);
        $headers = array();
        foreach ($multipleHeaders as $headerLine) {
            $header = new self();
            $keyValuePairs = preg_split('#;\s*#', $headerLine);
            foreach ($keyValuePairs as $keyValue) {
                if (strpos($keyValue, '=')) {
                    list($headerKey, $headerValue) = preg_split('#=\s*#', $keyValue, 2);
                } else {
                    $headerKey = $keyValue;
                    $headerValue = null;
                }
                
                // First K=V pair is always the cookie name and value
                if ($header->getName() === NULL) {
                    $header->setName($headerKey);
                    $header->setValue($headerValue);
                    continue;
                }

                // Process the remanining elements
                switch (str_replace(array('-', '_'), '', strtolower($headerKey))) {
                    case 'expires' : $header->setExpires($headerValue); break;
                    case 'domain'  : $header->setDomain($headerValue); break;
                    case 'path'    : $header->setPath($headerValue); break;
                    case 'secure'  : $header->setSecure(true); break;
                    case 'httponly': $header->setHttponly(true); break;
                    case 'version' : $header->setVersion((int) $headerValue); break;
                    case 'maxage'  : $header->setMaxAge((int) $headerValue); break;
                    default:
                        // Intentionally omitted
                }
            }
            $headers[] = $header;
        }
        return count($headers) == 1 ? array_pop($headers) : $headers;
    }