Generate a SpanContext object from the Trace Context header

@param string $header
@return SpanContext
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();
    }
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;
    }
332890
public function addHeader($header)
    {
        if (is_string($header)) {
            $header = HeaderField::fromString($header);
        }
        $this->headers[] = $header;
        return $this;
    }
1281279
public function setHeader($header)
    {
        $headers = [];

        if (is_array($header)) {
            foreach ($header as $key => $value) {
                $headers[] = $key . ': ' . $value;
            }
        } else {
            $headers[] = $header;
        }

        $this->setOpt(CURLOPT_HTTPHEADER, $headers);

        return $this;
    }
1249470
public function getRequestHeader($header)
    {
        $header = str_replace('-', '_', strtoupper($header));
        $value = $this->{'HTTP_' . $header};

        if (!$value) {
            $headers = $this->getRequestHeaders();
            $value = !empty($headers[$header]) ? $headers[$header] : null;
        }

        return $value;
    }
858666
protected function getHeaderStrArr($header)
    {
        $headerStr = [];
        foreach ($header as $co => $vo) {
            $headerStr[] = $this->ucWords($co) . ': ' . $vo;
        }
        return $headerStr;
    }
1053508
protected function getHeaderAdditions($header)
    {
        $insert = '';
        if ($this->injectDate) {
            $insert .= $this
                ->createTag($this->injectDate, (string)$header->datestamp);
        }
        if (isset($header->setSpec)
            && ($this->injectSetSpec || $this->injectSetName)
        ) {
            $insert .= $this->getHeaderSetAdditions($header->setSpec);
        }
        if ($this->injectHeaderElements) {
            foreach ($this->injectHeaderElements as $element) {
                if (isset($header->$element)) {
                    $insert .= $header->$element->asXML();
                }
            }
        }
        return $insert;
    }
146893
public function extract($headers)
    {
        if (array_key_exists($this->header, $headers)) {
            return $this->formatter->deserialize($headers[$this->header]);
        }
        return new SpanContext();
    }
124977
public function connectAsync(ConnectionContext $ctx, string $header = ''): \Generator
    {
        $this->ctx = $ctx->getCtx();
        $this->stream = yield $ctx->getStream(chr(239).$header);
    }
305962
private function parseHeader(string $header)
    {
        if (strpos($header, 'Digest') !== 0) {
            return false;
        }

        $needed_parts = [
            'nonce' => 1,
            'nc' => 1,
            'cnonce' => 1,
            'qop' => 1,
            'username' => 1,
            'uri' => 1,
            'response' => 1,
        ];

        $data = [];
        $regexp = '@('.implode('|', array_keys($needed_parts)).')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@';

        preg_match_all($regexp, substr($header, 7), $matches, PREG_SET_ORDER);

        if ($matches) {
            foreach ($matches as $m) {
                $data[$m[1]] = $m[3] ? $m[3] : $m[4];
                unset($needed_parts[$m[1]]);
            }
        }

        return empty($needed_parts) ? $data : false;
    }
575819
public function parseHeader($header)
    {
        $header = rtrim($header, "\r\n");
        $pieces = preg_split('@\s*[;,]\s*@', $header);
        $cookies = array();

        foreach ($pieces as $cookie) {
            $cookie = explode('=', $cookie, 2);

            if (count($cookie) === 2) {
                $key = urldecode($cookie[0]);
                $value = urldecode($cookie[1]);

                if (!isset($cookies[$key])) {
                    $cookies[$key] = $value;
                }
            }
        }

        return $cookies;
    }
892610
public function getHeader($header)
    {
        $header = ucwords(strtolower($header));
        if (! is_string($header) || ! isset($this->headers[$header])) return null;

        return $this->headers[$header];
    }
545388
public function withHeader($header): object
    {
        if (is_array($header)) {
            foreach ($header as $value) {
                header($value);
            }
        } else {
            header($header);
        }
        return $this;
    }
1189110
private SpanContext extract(HttpRequest request) {
    SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS,
        new HttpTextMapExtractAdapter(request));

    if (spanContext != null) {
      return spanContext;
    }

    Span span = tracer.activeSpan();
    if (span != null) {
      return span.context();
    }

    return null;
  }
568964
public static function getHeader($header) {

		$headers = static :: getHeaders();

		if(true === isset($headers[$header])) {
			return $headers[$header];
		}

		return null;
	}
954196
private function getRecordHeaderNode(Header $header)
    {
        $headerNode = $this->response->createElement('header');
        $headerNode->appendChild($this->response->createElement('identifier', $header->getIdentifier()));
        $headerNode->appendChild(
            $this->response->createElement('datestamp', $this->toUtcDateTime($header->getDatestamp()))
        );
        foreach ($header->getSetSpecs() as $setSpec) {
            $headerNode->appendChild($this->response->createElement('setSpec', $setSpec));
        }
        if ($header->isDeleted()) {
            $headerNode->setAttribute("status", "deleted");
        }
        return $headerNode;
    }
820816
public function connectAsync(ConnectionContext $ctx, string $header = ''): \Generator
    {
        $ctx = $ctx->getCtx();
        $uri = $ctx->getUri();
        $secure = $ctx->isSecure();
        $ctx->setUri('tcp://'.$this->extra['address'].':'.$this->extra['port'])->secure(false);

        $methods = chr(0);
        if (isset($this->extra['username']) && isset($this->extra['password'])) {
            $methods .= chr(2);
        }
        $this->stream = yield $ctx->getStream(chr(5).chr(strlen($methods)).$methods);
        $l = 2;
        $buffer = yield $this->stream->getReadBuffer($l);

        $version = ord(yield $buffer->bufferRead(1));
        $method = ord(yield $buffer->bufferRead(1));

        if ($version !== 5) {
            throw new \danog\MadelineProto\Exception("Wrong SOCKS5 version: $version");
        }
        if ($method === 2) {
            $auth = chr(1).chr(strlen($this->extra['username'])).$this->extra['username'].chr(strlen($this->extra['password'])).$this->extra['password'];
            yield $this->stream->write($auth);

            $buffer = yield $this->stream->getReadBuffer($l);

            $version = ord(yield $buffer->bufferRead(1));
            $result = ord(yield $buffer->bufferRead(1));

            if ($version !== 1) {
                throw new \danog\MadelineProto\Exception("Wrong authorized SOCKS version: $version");
            }
            if ($result !== 0) {
                throw new \danog\MadelineProto\Exception("Wrong authorization status: $version");
            }
        } elseif ($method !== 0) {
            throw new \danog\MadelineProto\Exception("Wrong method: $method");
        }
        $payload = pack('C3', 0x05, 0x01, 0x00);

        try {
            $ip = inet_pton($uri->getHost());
            $payload .= pack('C1', strlen($ip) === 4 ? 0x01 : 0x04).$ip;
        } catch (\danog\MadelineProto\Exception $e) {
            $payload .= pack('C2', 0x03, strlen($uri->getHost())).$uri->getHost();
        }
        $payload .= pack('n', $uri->getPort());
        yield $this->stream->write($payload);

        $l = 4;
        $buffer = yield $this->stream->getReadBuffer($l);

        $version = ord(yield $buffer->bufferRead(1));
        if ($version !== 5) {
            throw new \danog\MadelineProto\Exception("Wrong SOCKS5 version: $version");
        }

        $rep = ord(yield $buffer->bufferRead(1));
        if ($rep !== 0) {
            throw new \danog\MadelineProto\Exception("Wrong SOCKS5 rep: $rep");
        }

        $rsv = ord(yield $buffer->bufferRead(1));
        if ($rsv !== 0) {
            throw new \danog\MadelineProto\Exception("Wrong socks5 final RSV: $rsv");
        }
        switch (ord(yield $buffer->bufferRead(1))) {
            case 1:
                $buffer = yield $this->stream->getReadBuffer($l);
                $ip = inet_ntop(yield $buffer->bufferRead(4));
                break;
            case 4:
                $l = 16;
                $buffer = yield $this->stream->getReadBuffer($l);
                $ip = inet_ntop(yield $buffer->bufferRead(16));
                break;
            case 3:
                $l = 1;
                $buffer = yield $this->stream->getReadBuffer($l);
                $length = ord(yield $buffer->bufferRead(1));

                $buffer = yield $this->stream->getReadBuffer($length);
                $ip = yield $buffer->bufferRead($length);
                break;
        }
        $l = 2;
        $buffer = yield $this->stream->getReadBuffer($l);
        $port = unpack('n', yield $buffer->bufferRead(2))[1];
        \danog\MadelineProto\Logger::log(['Connected to '.$ip.':'.$port.' via socks5']);

        if ($secure && method_exists($this->stream, 'enableCrypto')) {
            yield $this->stream->enableCrypto();
        }
        if (strlen($header)) {
            yield (yield $this->stream->getWriteBuffer(strlen($header)))->bufferWrite($header);
        }
    }