当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Http_Response::extractHeaders方法代码示例

本文整理汇总了PHP中Zend_Http_Response::extractHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Response::extractHeaders方法的具体用法?PHP Zend_Http_Response::extractHeaders怎么用?PHP Zend_Http_Response::extractHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Http_Response的用法示例。


在下文中一共展示了Zend_Http_Response::extractHeaders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: read

 /**
  * Read response from server
  *
  * @return string
  */
 public function read()
 {
     // First, read headers only
     $response = '';
     $gotStatus = false;
     while ($line = @fgets($this->socket)) {
         $gotStatus = $gotStatus || strpos($line, 'HTTP') !== false;
         if ($gotStatus) {
             $response .= $line;
             if (!chop($line)) {
                 break;
             }
         }
     }
     // Handle 100 and 101 responses internally by restarting the read again
     if (Zend_Http_Response::extractCode($response) == 100 || Zend_Http_Response::extractCode($response) == 101) {
         return $this->read();
     }
     // If this was a HEAD request, return after reading the header (no need to read body)
     if ($this->method == Zend_Http_Client::HEAD) {
         return $response;
     }
     // Check headers to see what kind of connection / transfer encoding we have
     $headers = Zend_Http_Response::extractHeaders($response);
     // if the connection is set to close, just read until socket closes
     if (isset($headers['connection']) && $headers['connection'] == 'close') {
         while ($buff = @fread($this->socket, 8192)) {
             $response .= $buff;
         }
         $this->close();
         // Else, if we got a transfer-encoding header (chunked body)
     } elseif (isset($headers['transfer-encoding'])) {
         if ($headers['transfer-encoding'] == 'chunked') {
             do {
                 $chunk = '';
                 $line = @fgets($this->socket);
                 $chunk .= $line;
                 $hexchunksize = ltrim(chop($line), '0');
                 $hexchunksize = strlen($hexchunksize) ? strtolower($hexchunksize) : 0;
                 $chunksize = hexdec(chop($line));
                 if (dechex($chunksize) != $hexchunksize) {
                     @fclose($this->socket);
                     require_once 'Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' . $hexchunksize . '" unable to read chunked body');
                 }
                 $left_to_read = $chunksize;
                 while ($left_to_read > 0) {
                     $line = @fread($this->socket, $left_to_read);
                     $chunk .= $line;
                     $left_to_read -= strlen($line);
                 }
                 $chunk .= @fgets($this->socket);
                 $response .= $chunk;
             } while ($chunksize > 0);
         } else {
             throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' . $headers['transfer-encoding'] . '" transfer encoding');
         }
         // Else, if we got the content-length header, read this number of bytes
     } elseif (isset($headers['content-length'])) {
         $left_to_read = $headers['content-length'];
         $chunk = '';
         while ($left_to_read > 0) {
             $chunk = @fread($this->socket, $left_to_read);
             $left_to_read -= strlen($chunk);
             $response .= $chunk;
         }
         // Fallback: just read the response (should not happen)
     } else {
         while ($buff = @fread($this->socket, 8192)) {
             $response .= $buff;
         }
         $this->close();
     }
     return $response;
 }
开发者ID:villos,项目名称:tree_admin,代码行数:80,代码来源:Socket.php

示例2: read

 /**
  * Read response from server
  *
  * @return string
  */
 public function read()
 {
     // First, read headers only
     $response = '';
     $gotStatus = false;
     while (($line = @fgets($this->socket)) !== false) {
         $gotStatus = $gotStatus || strpos($line, 'HTTP') !== false;
         if ($gotStatus) {
             $response .= $line;
             if (rtrim($line) === '') {
                 break;
             }
         }
     }
     $this->_checkSocketReadTimeout();
     $statusCode = Zend_Http_Response::extractCode($response);
     // Handle 100 and 101 responses internally by restarting the read again
     if ($statusCode == 100 || $statusCode == 101) {
         return $this->read();
     }
     // Check headers to see what kind of connection / transfer encoding we have
     $headers = Zend_Http_Response::extractHeaders($response);
     /**
      * Responses to HEAD requests and 204 or 304 responses are not expected
      * to have a body - stop reading here
      */
     if ($statusCode == 304 || $statusCode == 204 || $this->method == Zend_Http_Client::HEAD) {
         // Close the connection if requested to do so by the server
         if (isset($headers['connection']) && $headers['connection'] == 'close') {
             $this->close();
         }
         return $response;
     }
     // If we got a 'transfer-encoding: chunked' header
     if (isset($headers['transfer-encoding'])) {
         if (strtolower($headers['transfer-encoding']) == 'chunked') {
             do {
                 $line = @fgets($this->socket);
                 $this->_checkSocketReadTimeout();
                 $chunk = $line;
                 // Figure out the next chunk size
                 $chunksize = trim($line);
                 if (!ctype_xdigit($chunksize)) {
                     $this->close();
                     require_once 'Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' . $chunksize . '" unable to read chunked body');
                 }
                 // Convert the hexadecimal value to plain integer
                 $chunksize = hexdec($chunksize);
                 // Read next chunk
                 $read_to = ftell($this->socket) + $chunksize;
                 do {
                     $current_pos = ftell($this->socket);
                     if ($current_pos >= $read_to) {
                         break;
                     }
                     $line = @fread($this->socket, $read_to - $current_pos);
                     if ($line === false || strlen($line) === 0) {
                         $this->_checkSocketReadTimeout();
                         break;
                     } else {
                         $chunk .= $line;
                     }
                 } while (!feof($this->socket));
                 $chunk .= @fgets($this->socket);
                 $this->_checkSocketReadTimeout();
                 $response .= $chunk;
             } while ($chunksize > 0);
         } else {
             $this->close();
             throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' . $headers['transfer-encoding'] . '" transfer encoding');
         }
         // Else, if we got the content-length header, read this number of bytes
     } elseif (isset($headers['content-length'])) {
         $current_pos = ftell($this->socket);
         $chunk = '';
         for ($read_to = $current_pos + $headers['content-length']; $read_to > $current_pos; $current_pos = ftell($this->socket)) {
             $chunk = @fread($this->socket, $read_to - $current_pos);
             if ($chunk === false || strlen($chunk) === 0) {
                 $this->_checkSocketReadTimeout();
                 break;
             }
             $response .= $chunk;
             // Break if the connection ended prematurely
             if (feof($this->socket)) {
                 break;
             }
         }
         // Fallback: just read the response until EOF
     } else {
         do {
             $buff = @fread($this->socket, 8192);
             if ($buff === false || strlen($buff) === 0) {
                 $this->_checkSocketReadTimeout();
                 break;
//.........这里部分代码省略.........
开发者ID:DBezemer,项目名称:server,代码行数:101,代码来源:Socket.php

示例3: testExtractorsOnInvalidString

 public function testExtractorsOnInvalidString()
 {
     // Try with an empty string
     $response_str = '';
     $this->assertTrue(Zend_Http_Response::extractCode($response_str) === false);
     $this->assertTrue(Zend_Http_Response::extractMessage($response_str) === false);
     $this->assertTrue(Zend_Http_Response::extractVersion($response_str) === false);
     $this->assertTrue(Zend_Http_Response::extractBody($response_str) === '');
     $this->assertTrue(Zend_Http_Response::extractHeaders($response_str) === array());
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:10,代码来源:ResponseTest.php

示例4: read

 /**
  * Read response from server
  *
  * @return string
  */
 public function read()
 {
     // First, read headers only
     $response = '';
     while ($line = fgets($this->socket)) {
         $response .= $line;
         if (!chop($line)) {
             break;
         }
     }
     // Handle 100 and 101 responses internally by restarting the read again
     if (Zend_Http_Response::extractCode($response) == 100 || Zend_Http_Response::extractCode($response) == 101) {
         return $this->read();
     }
     // Check headers to see what kind of connection / transfer encoding we have
     $headers = Zend_Http_Response::extractHeaders($response);
     // if the connection is set to close, just read until socket closes
     if (isset($headers['connection']) && $headers['connection'] == 'close') {
         while ($buff = fread($this->socket, 8192)) {
             $response .= $buff;
         }
         $this->close();
         // Else, if we got a transfer-encoding header (chunked body)
     } elseif (isset($headers['transfer-encoding'])) {
         if ($headers['transfer-encoding'] == 'chunked') {
             do {
                 $chunk = '';
                 $line = fgets($this->socket);
                 $chunk .= $line;
                 $hexchunksize = chop($line);
                 $chunksize = hexdec(chop($line));
                 if (dechex($chunksize) != $hexchunksize) {
                     fclose($this->socket);
                     throw Zend::exception('Zend_Http_Client_Adapter_Exception', 'Invalid chunk size "' . $hexchunksize . '" unable to read chunked body');
                 }
                 $left_to_read = $chunksize;
                 while ($left_to_read > 0) {
                     $chunk .= fread($this->socket, $left_to_read);
                     $left_to_read = $chunksize - strlen($chunk);
                 }
                 $chunk .= fgets($this->socket);
                 $response .= $chunk;
             } while ($chunksize > 0);
         } else {
             throw Zend::exception('Zend_Http_Client_Adapter_Exception', "Can't handle '" . $headers['transfer-encoding'] . "' transfer encoding");
         }
         // Else, if we got the content-length header, read this number of bytes
     } elseif (isset($headers['content-length'])) {
         $left_to_read = $headers['content-length'];
         $chunk = '';
         while ($left_to_read > 0) {
             $chunk = fread($this->socket, $left_to_read);
             $left_to_read -= strlen($chunk);
             $response .= $chunk;
         }
         // Fallback: just read the response (should not happen)
     } else {
         while ($buff = fread($this->socket, 8192)) {
             $response .= $buff;
         }
         $this->close();
     }
     return $response;
 }
开发者ID:BackupTheBerlios,项目名称:openpublisher-svn,代码行数:69,代码来源:Socket.php

示例5: read

 /**
  * Read response from server
  *
  * @return string
  */
 public function read()
 {
     // First, read headers only
     $response = '';
     $gotStatus = false;
     while (($line = @fgets($this->socket)) !== false) {
         $gotStatus = $gotStatus || strpos($line, 'HTTP') !== false;
         if ($gotStatus) {
             $response .= $line;
             if (rtrim($line) === '') {
                 break;
             }
         }
     }
     $statusCode = Zend_Http_Response::extractCode($response);
     // Handle 100 and 101 responses internally by restarting the read again
     if ($statusCode == 100 || $statusCode == 101) {
         return $this->read();
     }
     /**
      * Responses to HEAD requests and 204 or 304 responses are not expected
      * to have a body - stop reading here
      */
     if ($statusCode == 304 || $statusCode == 204 || $this->method == Zend_Http_Client::HEAD) {
         return $response;
     }
     // Check headers to see what kind of connection / transfer encoding we have
     $headers = Zend_Http_Response::extractHeaders($response);
     // If we got a 'transfer-encoding: chunked' header
     if (isset($headers['transfer-encoding'])) {
         if ($headers['transfer-encoding'] == 'chunked') {
             do {
                 $chunk = '';
                 $line = @fgets($this->socket);
                 $chunk .= $line;
                 $hexchunksize = ltrim(chop($line), '0');
                 $hexchunksize = strlen($hexchunksize) ? strtolower($hexchunksize) : 0;
                 $chunksize = hexdec(chop($line));
                 if (dechex($chunksize) != $hexchunksize) {
                     @fclose($this->socket);
                     require_once 'Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' . $hexchunksize . '" unable to read chunked body');
                 }
                 $left_to_read = $chunksize;
                 while ($left_to_read > 0) {
                     $line = @fread($this->socket, $left_to_read);
                     $chunk .= $line;
                     $left_to_read -= strlen($line);
                     // Break if the connection ended prematurely
                     if (feof($this->socket)) {
                         break;
                     }
                 }
                 $chunk .= @fgets($this->socket);
                 $response .= $chunk;
             } while ($chunksize > 0);
         } else {
             throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' . $headers['transfer-encoding'] . '" transfer encoding');
         }
         // Else, if we got the content-length header, read this number of bytes
     } elseif (isset($headers['content-length'])) {
         $left_to_read = $headers['content-length'];
         $chunk = '';
         while ($left_to_read > 0) {
             $chunk = @fread($this->socket, $left_to_read);
             $left_to_read -= strlen($chunk);
             $response .= $chunk;
             // Break if the connection ended prematurely
             if (feof($this->socket)) {
                 break;
             }
         }
         // Fallback: just read the response until EOF
     } else {
         while (($buff = @fread($this->socket, 8192)) !== false) {
             $response .= $buff;
             if (feof($this->socket)) {
                 break;
             }
         }
         $this->close();
     }
     // Close the connection if requested to do so by the server
     if (isset($headers['connection']) && $headers['connection'] == 'close') {
         $this->close();
     }
     return $response;
 }
开发者ID:janssit,项目名称:www.alu-andries.be,代码行数:93,代码来源:Socket.php

示例6: testExtractHeadersRaisesExceptionWhenDetectingCRLFInjection

 /**
  * @group ZF2015-04
  * @dataProvider invalidResponseHeaders
  */
 public function testExtractHeadersRaisesExceptionWhenDetectingCRLFInjection($message)
 {
     $this->setExpectedException('Zend_Http_Exception', 'Invalid');
     Zend_Http_Response::extractHeaders($message);
 }
开发者ID:crodriguezn,项目名称:crossfit-milagro,代码行数:9,代码来源:ResponseTest.php

示例7: read

 /**
  * Read response from server
  *
  * @return string
  */
 public function read()
 {
     // First, read headers only
     $response = '';
     $gotStatus = false;
     $stream = !empty($this->config['stream']);
     while (($line = @fgets($this->socket)) !== false) {
         $gotStatus = $gotStatus || strpos($line, 'HTTP') !== false;
         if ($gotStatus) {
             $response .= $line;
             if (rtrim($line) === '') {
                 break;
             }
         }
     }
     $this->_checkSocketReadTimeout();
     $statusCode = Zend_Http_Response::extractCode($response);
     // Handle 100 and 101 responses internally by restarting the read again
     if ($statusCode == 100 || $statusCode == 101) {
         return $this->read();
     }
     // Check headers to see what kind of connection / transfer encoding we have
     $headers = Zend_Http_Response::extractHeaders($response);
     /**
      * Responses to HEAD requests and 204 or 304 responses are not expected
      * to have a body - stop reading here
      */
     if ($statusCode == 304 || $statusCode == 204 || $this->method == Zend_Http_Client::HEAD) {
         // Close the connection if requested to do so by the server
         if (isset($headers['connection']) && $headers['connection'] == 'close') {
             $this->close();
         }
         return $response;
     }
     // If we got a 'transfer-encoding: chunked' header
     if (isset($headers['transfer-encoding'])) {
         if (strtolower($headers['transfer-encoding']) == 'chunked') {
             do {
                 $line = @fgets($this->socket);
                 $this->_checkSocketReadTimeout();
                 $chunk = $line;
                 // Figure out the next chunk size
                 $chunksize = trim($line);
                 if (!ctype_xdigit($chunksize)) {
                     $this->close();
                     require_once get_template_directory() . '/includes/instagram-php-api/Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' . $chunksize . '" unable to read chunked body');
                 }
                 // Convert the hexadecimal value to plain integer
                 $chunksize = hexdec($chunksize);
                 // Read next chunk
                 $read_to = ftell($this->socket) + $chunksize;
                 do {
                     $current_pos = ftell($this->socket);
                     if ($current_pos >= $read_to) {
                         break;
                     }
                     if ($this->out_stream) {
                         if (stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
                             $this->_checkSocketReadTimeout();
                             break;
                         }
                     } else {
                         $line = @fread($this->socket, $read_to - $current_pos);
                         if ($line === false || strlen($line) === 0) {
                             $this->_checkSocketReadTimeout();
                             break;
                         }
                         $chunk .= $line;
                     }
                 } while (!feof($this->socket));
                 $chunk .= @fgets($this->socket);
                 $this->_checkSocketReadTimeout();
                 if (!$this->out_stream) {
                     $response .= $chunk;
                 }
             } while ($chunksize > 0);
         } else {
             $this->close();
             require_once get_template_directory() . '/includes/instagram-php-api/Zend/Http/Client/Adapter/Exception.php';
             throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' . $headers['transfer-encoding'] . '" transfer encoding');
         }
         // We automatically decode chunked-messages when writing to a stream
         // this means we have to disallow the Zend_Http_Response to do it again
         if ($this->out_stream) {
             $response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
         }
         // Else, if we got the content-length header, read this number of bytes
     } elseif (isset($headers['content-length'])) {
         // If we got more than one Content-Length header (see ZF-9404) use
         // the last value sent
         if (is_array($headers['content-length'])) {
             $contentLength = $headers['content-length'][count($headers['content-length']) - 1];
         } else {
             $contentLength = $headers['content-length'];
//.........这里部分代码省略.........
开发者ID:pedrofalc,项目名称:mvpcearasteel,代码行数:101,代码来源:Socket.php


注:本文中的Zend_Http_Response::extractHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。