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


PHP HttpResponse::getHeaders方法代码示例

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


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

示例1: testGetters

 public function testGetters()
 {
     $response = new HttpResponse(200, array('Age: 42'), 'Hey');
     $this->assertEquals(200, $response->getStatus());
     $this->assertEquals(array('Age: 42'), $response->getHeaders());
     $this->assertEquals('Hey', $response->getBody());
 }
开发者ID:phpcurl,项目名称:curlhttp,代码行数:7,代码来源:HttpResponseTest.php

示例2: getHttpException

 /**
  * Retrive http exception from HttpResponse object.
  *
  * @param HttpResponse $httpResponse
  * @return string
  */
 protected function getHttpException($httpResponse)
 {
     $exception = '';
     $headers = $httpResponse->getHeaders();
     if (isset($headers['Content-type'])) {
         if (strpos(strtolower($headers['Content-type']), strtolower(Resource::Content_Type_ATOM)) !== FALSE) {
             $exception = $httpResponse->getMessage();
         } else {
             $exception = $httpResponse->getBody();
         }
     } else {
         $exception = $httpResponse->getMessage();
     }
     return $exception;
 }
开发者ID:silviogarbes,项目名称:phpodata,代码行数:21,代码来源:SaveResult.php

示例3: HttpResponse

 private function &serveFile()
 {
     // Serve file - we can do this using the writeFile() method, which is memory friendly
     $r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 200);
     // Cache?
     $useCache = false;
     $scriptnameHash = md5($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']);
     if (isset($this->httpRequest->headers['Cache-Control']) || isset($this->httpRequest->headers['Pragma'])) {
         $ifModifiedSince = isset($this->httpRequest->headers['If-Modified-Since']) ? (int) strtotime($this->httpRequest->headers['If-Modified-Since']) : 0;
         $cacheControl = isset($this->httpRequest->headers['Cache-Control']) ? $this->httpRequest->parseHeaderValue($this->httpRequest->headers['Cache-Control']) : array();
         $pragma = isset($this->httpRequest->headers['Pragma']) ? $this->httpRequest->parseHeaderValue($this->httpRequest->headers['Pragma']) : array();
         // Detect 'If-Modified-Since' (weak) cache validator (http1.1)
         if ($ifModifiedSince > 0) {
             if (isset($this->http->cache[$scriptnameHash])) {
                 if ($this->http->cache[$scriptnameHash] == $ifModifiedSince) {
                     // File has not been changed - tell the browser to use the cache (send a 304)
                     $useCache = true;
                 }
             } else {
                 $scriptMTime = filemtime($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']);
                 $this->http->cache[$scriptnameHash] = $scriptMTime;
                 if ($scriptMTime == $ifModifiedSince) {
                     // File has not been changed - tell the browser to use the cache (send a 304)
                     $useCache = true;
                 }
             }
         } else {
             if (isset($cacheControl['max-age']) && $cacheControl['max-age'] == 0 && $cacheControl != 'no-cache' && $pragma != 'no-cache' && isset($this->http->cache[$scriptnameHash])) {
                 $scriptMTime = filemtime($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']);
                 if ($this->http->cache[$scriptnameHash] == $scriptMTime) {
                     // File has not been changed - tell the browser to use the cache (send a 304)
                     $useCache = true;
                 } else {
                     // File has been updated - store new mtime in cache
                     $this->http->cache[$scriptnameHash] = $scriptMTime;
                 }
                 clearstatcache();
             }
         }
     }
     if ($useCache) {
         $r->setResponseCode(304);
         $this->write($r->getHeaders());
     } else {
         $scriptMTime = filemtime($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']);
         $r->addHeader('Content-Type: ' . $this->getMimeType());
         $r->addHeader('Last-Modified: ' . date('r', $scriptMTime));
         if (isset($this->httpRequest->SERVER['HTTP_RANGE'])) {
             console('HTTP_RANGE HEADER : ' . $this->httpRequest->SERVER['HTTP_RANGE']);
             $exp = explode('=', $this->httpRequest->SERVER['HTTP_RANGE']);
             $startByte = (int) substr($exp[1], 0, -1);
             $r->addHeader('Content-Length: ' . (filesize($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']) - $startByte));
             $this->write($r->getHeaders());
             $this->writeFile($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME'], $startByte);
         } else {
             $r->addHeader('Content-Length: ' . filesize($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']));
             $this->write($r->getHeaders());
             $this->writeFile($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME']);
         }
         // Store the filemtime in $cache
         if (!isset($this->http->cache[$scriptnameHash])) {
             $this->http->cache[$scriptnameHash] = $scriptMTime;
         }
         clearstatcache();
     }
     return $r;
 }
开发者ID:jkaplavka,项目名称:PRISM,代码行数:67,代码来源:prism_http.php

示例4: executeRequest

 /**
  * Execute an HTTP request and return the results
  *
  * This function will throw if no connection to the server can be established or if
  * there is a problem during data exchange with the server.
  *
  * will restore it.
  *
  * @throws Exception
  *
  * @param string $method       - HTTP request method
  * @param string $url          - HTTP URL
  * @param string $data         - data to post in body
  * @param array  $customHeader - any array containing header elements
  *
  * @return HttpResponse
  */
 private function executeRequest($method, $url, $data, $customHeader = array())
 {
     HttpHelper::validateMethod($method);
     $database = $this->getDatabase();
     if ($database === '') {
         $url = '/_db/' . '_system' . $url;
     } else {
         $url = '/_db/' . $database . $url;
     }
     // create request data
     if ($this->_batchRequest === false) {
         if ($this->_captureBatch === true) {
             $this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, true);
             $request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
             $this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, false);
         } else {
             $request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
         }
         if ($this->_captureBatch === true) {
             $batchPart = $this->doBatch($method, $request);
             if (!is_null($batchPart)) {
                 return $batchPart;
             }
         }
     } else {
         $this->_batchRequest = false;
         $this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, true);
         $request = HttpHelper::buildRequest($this->_options, $method, $url, $data, $customHeader);
         $this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, false);
     }
     $traceFunc = $this->_options[ConnectionOptions::OPTION_TRACE];
     if ($traceFunc) {
         // call tracer func
         if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
             list($header) = HttpHelper::parseHttpMessage($request, $url, $method);
             $headers = HttpHelper::parseHeaders($header);
             $traceFunc(new TraceRequest($headers[2], $method, $url, $data));
         } else {
             $traceFunc('send', $request);
         }
     }
     // open the socket. note: this might throw if the connection cannot be established
     $handle = $this->getHandle();
     if ($handle) {
         // send data and get response back
         if ($traceFunc) {
             // only issue syscall if we need it
             $startTime = microtime(true);
         }
         $result = HttpHelper::transfer($handle, $request);
         if ($traceFunc) {
             // only issue syscall if we need it
             $timeTaken = microtime(true) - $startTime;
         }
         $status = socket_get_status($handle);
         if ($status['timed_out']) {
             throw new ClientException('Got a timeout while waiting for the server\'s response', 408);
         }
         if (!$this->_useKeepAlive) {
             // must close the connection
             fclose($handle);
         }
         $response = new HttpResponse($result, $url, $method);
         if ($traceFunc) {
             // call tracer func
             if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
                 $traceFunc(new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody(), $timeTaken));
             } else {
                 $traceFunc('receive', $result);
             }
         }
         return $response;
     }
     throw new ClientException('Whoops, this should never happen');
 }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:92,代码来源:Connection.php


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