Returns the fixed header part needed for all methods

This takes into account the basic control packet value, any special flags and, in the second byte, the variable
header length

@param int $variableHeaderLength
@return string
@throws MessageTooBig
546945
final public function createFixedHeader(int $variableHeaderLength): string
    {
        $this->logger->debug('Creating fixed header with values', [
            'controlPacketValue' => self::getControlPacketValue(),
            'specialFlags' => $this->specialFlags,
            'variableHeaderLength' => $variableHeaderLength,
            'composed' => decbin(chr((self::getControlPacketValue() << 4) | $this->specialFlags)),
        ]);

        // Binary OR is safe to do because the first 4 bits are always 0 after shifting
        return
            chr((self::getControlPacketValue() << 4) | $this->specialFlags) .
            Utilities::formatRemainingLengthOutput($variableHeaderLength);
    }
818563
public function parseHeader($header)
    {
        $parsed_header = array();

        $header_lines = explode("\r\n", $header);
        if (count($header_lines) > 0) {
            foreach ($header_lines as $line) {
                $header = explode(':', $line);
                if (count($header) > 1) {
                    $label = array_shift($header);

                    $value = $header;
                    $value = implode(':', $header);
                    $value = trim($value);

                    $parsed_header[$label] = $value;
                }
            }
        }

        return $parsed_header;
    }
885350
private function getHttpHeadersAsString($headers)
    {
        if (count($headers) == 0) {
            return '';
        }

        $max = max(array_map('strlen', array_keys($headers))) + 1;
        $content = '';
        ksort($headers);
        foreach ($headers as $name => $values) {
            foreach ($values as $value) {
                $content .= sprintf("%-{$max}s %s\r\n", $this->beautifyHeaderName($name).':', $value);
            }
        }

        return $content;
    }
1327351
public static function encodeHeader(Header $header): string
    {
        return pack(
            'nnnnnn',
            $header->getId(),
            self::encodeFlags($header),
            $header->getQuestionCount(),
            $header->getAnswerCount(),
            $header->getNameServerCount(),
            $header->getAdditionalRecordsCount()
        );
    }
395005
public function getHeader($header)
    {
        if (array_key_exists($header, $this->responseHeaders)) {
            return $this->responseHeaders[$header];
        }
        // Do case-insensitive search
        foreach ($this->responseHeaders as $k => $v) {
            if (strtolower($k) == strtolower($header)) {
                return $v;
            }
        }
    }
471488
private static function getHeaderIp($header): ?string
    {
        foreach (\array_map('\trim', \explode(',', $header)) as $ip) {
            if (self::isValid($ip)) {
                return $ip;
            }
        }

        return null;
    }
270921
public static function fixContentLength(MessageInterface $response): MessageInterface
    {
        $size = $response->getBody()->getSize();
        if ($size !== null) {
            return $response->withHeader('Content-Length', (string) $size);
        }

        return $response->withoutHeader('Content-Length');
    }
454319
public function getObjectLength()
    {
        $nrOfIdentifierOctets = strlen($this->getIdentifier());
        $contentLength = $this->getContentLength();
        $nrOfLengthOctets = $this->getNumberOfLengthOctets($contentLength);

        return $nrOfIdentifierOctets + $nrOfLengthOctets + $contentLength;
    }
1029848
public function getHeader($header)
	{
		$n = ($header instanceof HttpHeaderInterface) ? strtolower($header->getFieldName()) : strtolower($header);
		
		if(!empty($this->headers[$n]))
		{
			return $this->headers[$n][0][1];
		}
		
		if(func_num_args() > 1)
		{
			return func_get_arg(1);
		}
		
		$name = ($header instanceof HttpHeaderInterface) ? $header->getFieldName() : $header;
		
		throw new \OutOfBoundsException(sprintf('HTTP header not found: "%s"', $name));
	}
640246
protected function buildVariableHeader()
    {
        $buffer = "";
        $buffer .= chr($this->session_present);
        $buffer .= chr($this->return_code);
        return $buffer;
    }
1113650
private function getNextVariableName()
    {
        $firstChars = self::FIRST_CHARS;
        $firstCharsLength = strlen($firstChars);
        $nonFirstChars = self::NON_FIRST_CHARS;
        $nonFirstCharsLength = strlen($nonFirstChars);

        while (true) {
            $name = '';
            $i = $this->variableCount;

            if ('' === $name) {
                $name .= $firstChars[$i % $firstCharsLength];
                $i = (int) ($i / $firstCharsLength);
            }

            while ($i > 0) {
                --$i;
                $name .= $nonFirstChars[$i % $nonFirstCharsLength];
                $i = (int) ($i / $nonFirstCharsLength);
            }

            ++$this->variableCount;

            // check that the name is not reserved
            if (in_array($name, $this->reservedVariables, true)) {
                continue;
            }

            return $name;
        }
    }
261367
public function getHeadersString(\Psr\Http\Message\ResponseInterface $psr7response)
    {
        $strHeaders = '';
        if($psr7response === null)
        {
            return $strHeaders;
        }

        $arrHeaders = $psr7response->getHeaders();
        if (!is_array($arrHeaders) || count($arrHeaders) < 1) {
            return '';
        }

        foreach ($arrHeaders as $key => $value) {

            $strVal = '';
            if(is_array($value) && count($value)>0){
                $strVal = $value[0];

            }elseif (is_string($value)){
                $strVal = $value;
            }

            $strHeaders .= $key.':'.$strVal.PHP_EOL;
        }

        return $strHeaders;
    }
403591
protected function _getHeaderHandleName()
    {
        $handleCode = $this->_scopeConfig->getValue(
            self::HEADER_LAYOUT_CONFIG_PATH,
            ScopeInterface::SCOPE_STORE
        );
        if (!$handleCode) {
            $handleCode = 1;
        }
        return self::HEADER_LAYOUT_HANDLE_PREFIX . $handleCode;
    }
664235
final protected function processReadFixedHeaderWithMsgID($message)
    {
        $packet_length = 4;
        $name = Message::$name[$this->message_type];

        if (!isset($message[$packet_length - 1])) {
            # error
            Debug::Log(Debug::DEBUG, "Message {$name}: error on reading");
            return false;
        }

        $packet = unpack('Ccmd/Clength/nmsgid', $message);

        $packet['cmd'] = Utility::UnpackCommand($packet['cmd']);

        if ($packet['cmd']['message_type'] != $this->getMessageType()) {
            Debug::Log(Debug::DEBUG, "Message {$name}: type mismatch");
            return false;
        } else {
            Debug::Log(Debug::DEBUG, "Message {$name}: success");
            return $packet;
        }
    }
1160541
final public function createSendableMessage(): string
    {
        $variableHeader = $this->createVariableHeader();
        $this->logger->debug('Created variable header', ['variableHeader' => base64_encode($variableHeader)]);
        $payload = $this->createPayload();
        $this->logger->debug('Created payload', ['payload' => base64_encode($payload)]);
        $fixedHeader = $this->createFixedHeader(strlen($variableHeader . $payload));
        $this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);

        return $fixedHeader . $variableHeader . $payload;
    }
803161
private static int getWebSocketContentLength(HttpMessage message) {
        // WebSocket messages have constant content-lengths.
        HttpHeaders h = message.headers();
        if (message instanceof HttpRequest) {
            HttpRequest req = (HttpRequest) message;
            if (HttpMethod.GET.equals(req.method()) &&
                    h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY1) &&
                    h.contains(HttpHeaderNames.SEC_WEBSOCKET_KEY2)) {
                return 8;
            }
        } else if (message instanceof HttpResponse) {
            HttpResponse res = (HttpResponse) message;
            if (res.status().code() == 101 &&
                    h.contains(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN) &&
                    h.contains(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)) {
                return 16;
            }
        }

        // Not a web socket message
        return -1;
    }
317984
protected static function getRequestSize($header, $method)
    {
        if($method === 'GET' || $method === 'OPTIONS' || $method === 'HEAD') {
            return strlen($header) + 4;
        }
        $match = array();
        if (preg_match("/\r\nContent-Length: ?(\d+)/i", $header, $match)) {
            $content_length = isset($match[1]) ? $match[1] : 0;
            return $content_length + strlen($header) + 4;
        }
        return $method === 'DELETE' ? strlen($header) + 4 : 0;
    }