握手
@param $headerBuffer
@return bool
350693
function doHandShake($headerBuffer)
    {
        $header = Swoole\Http\Parser::parseHeader($headerBuffer);
        $_header_key_low_case = array_change_key_case($header, CASE_LOWER);
        if (!isset($_header_key_low_case['sec-websocket-accept']))
        {
            $this->disconnect();
            return false;
        }
        if ($_header_key_low_case['sec-websocket-accept'] != base64_encode(pack('H*', sha1($this->key . self::GUID))))
        {
            $this->disconnect();
            return false;
        }
        $this->handshake = true;
        $this->header = $header;
        return true;
    }
1246785
private function handleBuffer($buffer) {
        $error = error_get_last();

        if ( $error ) {
            $matches = [];
            preg_match('/\: (.*) in /', $error['message'], $matches);
            $message = key_exists(1, $matches) ? $matches[1] : $error['message'];
            
            /* @var $response \PowerOn\Network\Response */
            $response = $this->_container['Response'];
            
            if ( DEV_ENVIRONMENT ) {
                $response->setHeader(500);
                return 
                      '<header>'
                        . '<h1>Error: ' . $message . '</h1>'
                        . '<h2>' . $error['file'] . ' (' . $error['line'] . ')</h2>'
                    . '</header>';
            } else {
                /* @var $logger \Monolog\Logger */
                $logger = $this->_container['Logger'];
                $logger->error($message, [
                    'type' => $error['type'],
                    'file' => $error['file'],
                    'line' => $error['line']
                ]);

                /* @var $router \AltoRouter */
                $router = $this->_container['AltoRouter'];

                $response->redirect( $router->generate('poweron_error', ['error' => 500]) );
            }
        }

        return $buffer;
    }
48906
public function header($header = null) {
			if ($this->_status != null) {
				array_push($this->_headers, $header);
				return true;
			}
			else {
				return $this->_headers;
			}
		}
118498
public static function parseHeaders($headerstr=false) {
        if ( $headerstr === false ) $headerstr = self::getLastHeadersReceived();
        $lines = explode("\n",$headerstr);
        $headermap = array();

        foreach ($lines as $line) {
            $pos = strpos($line, ':');
            if ( $pos < 1 ) continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line, $pos+1));
            if ( strlen($key) < 1 || strlen($value) < 1 ) continue;
            $headermap[$key] = $value;
        }
        return $headermap;
    }
790241
public function sendSms($mobile, $text)
    {
        if ($this->useFileTransport) {
            return $this->saveSms($mobile, $text);
        }

        if (!is_array($mobile)) {
            $mobile = explode(',', $mobile);
        }

        if (empty($mobile)) {
            $this->setError("手机号不得为空");

            return false;
        }

        $mobileArr = array_chunk($mobile, 90);
        $mobile = array_pop($mobileArr);
        foreach ($mobileArr as $val) {
            self::sendSms($val, $text);
        }

        $mobile = array_filter($mobile, function ($val) {
            $isPhoneNumber = strlen($val) === 11;
            if ($isPhoneNumber) {
                return true;
            } else {
                $this->setError("Error phone number: " . $val);

                return false;
            }
        });

        $body = ['mobile' => implode(',', $mobile), 'text' => $text,];
        $url = sprintf($this->urlFormat, self::RESOURCE_SMS, self::FUNCTION_SEND);

        if (($body = $this->post($url, $body)) === false) {
            return false;
        }

        $code = $body['code'];
        if ($code != self::CODE_0) {
            $n = new ConstDocHelper(__CLASS__);
            if ($code < 0) {
                $const = 'CODE_N' . (-$code);
            } else {
                $const = 'CODE_' . $code;
            }
            $this->setError($n->getDocComment($const), $code, $body['detail']);

            return false;
        }
        $this->body = $body;

        return true;
    }
1103449
public function formatHeaderAndRemovePrefix($header, $prefix = 'HTTP_') {
        if (str_starts_with($header, $prefix)) {
            $header = substr($header, strlen($prefix));
        }

        return $this->formatHeader($header);
    }
912048
private function hasHeader()
    {
        if ($this->min === 0 || $this->isAddButtonPositionHeader()) {
            return true;
        }

        foreach ($this->columns as $column) {
            /* @var $column BaseColumn */
            if ($column->title) {
                return true;
            }
        }

        return false;
    }
1342268
public function hash($buffer)
    {
        // already loaded phpass?
        if (self::$passwordHash === null) {
            include_once DOOZR_DOCUMENT_ROOT.'Service/Doozr/Password/Service/Lib/Hash.php';
            self::$passwordHash = new Doozr_Password_Service_Hash(8, false);
        }

        // return the calculated hash
        return self::$passwordHash->HashPassword($buffer);
    }
395230
public function headersToCurl(array $headers)
    {
        $this->formatedParameters = [];
        $curlHeaders              = '';

        foreach ($headers as $headerName => $values) {
            foreach ($values as $headerValue) {
                $curlHeaders .= sprintf('--header "%s: %s" ', $headerName, $headerValue);
            }
        }

        return substr($curlHeaders, 0, -1);
    }
271365
private static function parseRangeHeader($header)
    {
        if (preg_match('/bytes=(?P<first>\d+)-(?P<last>\d+)?/', $header, $matches)) {
            return [
                (int) $matches['first'],
                isset($matches['last']) ? (int) $matches['last'] : null,
            ];
        }

        return false;
    }
632874
private function detectFrameHead()
    {
        $firstCrLf = strpos($this->buffer, self::HEADER_STOP_CR_LF, $this->offset);
        $firstLf = strpos($this->buffer, self::HEADER_STOP_LF, $this->offset);

        // we need to use the first available marker, so we need to make sure that cr lf don't overrule lf
        if ($firstCrLf !== false && ($firstLf === false || $firstLf > $firstCrLf)) {
            $this->extractFrameMeta(substr($this->buffer, $this->offset, $firstCrLf - $this->offset));
            $this->offset = $firstCrLf + strlen(self::HEADER_STOP_CR_LF);
            return true;
        }

        if ($firstLf !== false) {
            $this->extractFrameMeta(substr($this->buffer, $this->offset, $firstLf - $this->offset));
            $this->offset = $firstLf + strlen(self::HEADER_STOP_LF);
            return true;
        }
        return false;
    }
414454
public function handleFatalBuffer($buffer)
    {
        $e = error_get_last();
        return ($e !== null && in_array($e['type'], $this->fatalErrorTypes)) ? '' : $buffer;
    }
243168
public function shouldBuffer($buffer)
    {
        if ('' === $buffer) {
            return false;
        }

        $endOfBuffer = substr($buffer, -1);
        foreach ((array) $this->search as $needle) {
            if (false !== strpos($needle, $endOfBuffer)) {
                return true;
            }
        }

        return false;
    }
1186392
private function _processHtmlTitleMarker(&$pBuffer)
	{
		$title = ($this->_titlePrefix and $this->_title) ? $this->_titlePrefix . $this->_titleSeparator . $this->_title : $this->_titlePrefix . $this->_title;
		$pBuffer = str_replace(self::getTitleMarker(), $title, $pBuffer);

		if (! isset($this->_meta['itemprop.name'])) {
			$this->addMeta('itemprop.name', array(
				'itemprop' => 'name',
				'content'  => $title
			));
		}

		if (! isset($this->_meta['og:title'])) {
			$this->addMeta('og:title', array(
				'property' => 'og:title',
				'content'  => $title
			));
		}

		return $this;
	}
1213434
private function parseHeader(HeaderBag $headerBag)
    {
        try {
            $vars = $this->consumeRegexp('/('.self::TOKEN_HEADER_NAME.'): ?/');
            $headerName = $vars[1];
            $value      = $this->consumeTo("\n");
            $this->consume("\n");
            while ($this->expects(" ") || $this->expects("\t")) {
                $value .= $this->consumeTo("\n");
                $this->consume("\n");
            }

            $headerBag->set($headerName, $value);
        } catch (\InvalidArgumentException $e) {
            return false;
        }

        return true;
    }
714917
public function checkHttpHeadersForMobile()
        {
            foreach($this->getMobileHeaders() as $mobileHeader => $matchType) {
                if(isset($this->httpHeaders[$mobileHeader])) {
                    if(Arrays::is($matchType['matches'])) {
                        foreach($matchType['matches'] as $_match) {
                            if(strpos($this->httpHeaders[$mobileHeader], $_match) !== false) {
                                return true;
                            }
                        }
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            return false;
        }
389999
function _unpad($text)
    {
        if (!$this->padding) {
            return $text;
        }

        $length = ord($text[strlen($text) - 1]);

        if (!$length || $length > $this->block_size) {
            return false;
        }

        return substr($text, 0, -$length);
    }