parseHeaderLine() static public method

传入一个字符串或者数组
static public parseHeaderLine ( $headerLines ) : array
$headerLines string/array
return array
コード例 #1
0
ファイル: HttpClient.php プロジェクト: jasonshaw/framework-1
 function parseHeader($data)
 {
     $parts = explode("\r\n\r\n", $data, 2);
     // parts[0] = HTTP头;
     // parts[1] = HTTP主体,GET请求没有body
     $headerLines = explode("\r\n", $parts[0]);
     // HTTP协议头,方法,路径,协议[RFC-2616 5.1]
     list($status['method'], $status['uri'], $status['protocol']) = explode(' ', $headerLines[0], 3);
     //错误的HTTP请求
     if (empty($status['method']) or empty($status['uri']) or empty($status['protocol'])) {
         return false;
     }
     unset($headerLines[0]);
     //解析Header
     $this->respHeader = \Swoole\Http\Parser::parseHeaderLine($headerLines);
     $this->status = $status;
     if (isset($parts[1])) {
         $this->buffer = $parts[1];
     }
     return true;
 }
コード例 #2
0
ファイル: HTTP.php プロジェクト: rockylo/tsf
 private function parseHeader($data)
 {
     $parts = explode("\r\n\r\n", $data, 2);
     $headerLines = explode("\r\n", $parts[0]);
     list($this->rspHeaders['method'], $this->rspHeaders['uri'], $this->rspHeaders['protocol']) = explode(' ', $headerLines[0], 3);
     $this->respHeader = \Swoole\Http\Parser::parseHeaderLine($headerLines);
     if (isset($parts[1])) {
         $this->content = $parts[1];
     }
     //print_r($this ->respHeader);
     \SysLog::info(__METHOD__ . " header == " . print_r($this->respHeader, true), __CLASS__);
 }