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


PHP Response::getHeader方法代码示例

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


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

示例1: getRateReset

 /**
  * Seconds remaining until a new time window opens
  *
  * @return null
  */
 public function getRateReset()
 {
     if (!$this->lastResponse) {
         return null;
     }
     /** @var Header $limit */
     $limit = $this->lastResponse->getHeader('X-Rate-Reset');
     return $limit ? $limit->normalize() : null;
 }
开发者ID:javihgil,项目名称:genderize-io-client,代码行数:14,代码来源:GenderizeClient.php

示例2: testOnRequestSuccess

 public function testOnRequestSuccess()
 {
     $event = new Event();
     $response = new Response(200, array('X-RateLimit-Limit' => array(30), 'X-RateLimit-Remaining' => array(29), 'X-RateLimit-Reset' => array(10)));
     $event['response'] = $response;
     $plugin = new RateLimitPlugin();
     $plugin->onRequestSuccess($event);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Limit'), 'rateLimitMax', $plugin);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Remaining'), 'rateLimitRemaining', $plugin);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Reset'), 'rateLimitReset', $plugin);
     $this->assertAttributeEquals(true, 'rateLimitEnabled', $plugin);
 }
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:12,代码来源:RateLimitPluginTest.php

示例3: getLatestResponseHeaders

 /**
  * {@inheritdoc}
  */
 public function getLatestResponseHeaders()
 {
     if (null === $this->response) {
         return;
     }
     return ['reset' => (int) (string) $this->response->getHeader('RateLimit-Reset'), 'remaining' => (int) (string) $this->response->getHeader('RateLimit-Remaining'), 'limit' => (int) (string) $this->response->getHeader('RateLimit-Limit')];
 }
开发者ID:skaisser,项目名称:upcloud,代码行数:10,代码来源:GuzzleAdapter.php

示例4: getApiLimit

 public static function getApiLimit(Response $response)
 {
     $remainingCalls = $response->getHeader('X-RateLimit-Remaining');
     if (null !== $remainingCalls && 1 > $remainingCalls) {
         throw new ApiLimitExceedException($remainingCalls);
     }
 }
开发者ID:alnutile,项目名称:saucelabs_client,代码行数:7,代码来源:ResponseMediator.php

示例5: cache

 public function cache(RequestInterface $request, Response $response)
 {
     $currentTime = time();
     $ttl = $request->getParams()->get('cache.override_ttl') ?: $response->getMaxAge() ?: $this->defaultTtl;
     if ($cacheControl = $response->getHeader('Cache-Control')) {
         $stale = $cacheControl->getDirective('stale-if-error');
         $ttl += $stale == true ? $ttl : $stale;
     }
     // Determine which manifest key should be used
     $key = $this->getCacheKey($request);
     $persistedRequest = $this->persistHeaders($request);
     $entries = array();
     if ($manifest = $this->cache->fetch($key)) {
         // Determine which cache entries should still be in the cache
         $vary = $response->getVary();
         foreach (unserialize($manifest) as $entry) {
             // Check if the entry is expired
             if ($entry[4] < $currentTime) {
                 continue;
             }
             $entry[1]['vary'] = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
             if ($vary != $entry[1]['vary'] || !$this->requestsMatch($vary, $entry[0], $persistedRequest)) {
                 $entries[] = $entry;
             }
         }
     }
     // Persist the response body if needed
     $bodyDigest = null;
     if ($response->getBody() && $response->getBody()->getContentLength() > 0) {
         $bodyDigest = $this->getBodyKey($request->getUrl(), $response->getBody());
         $this->cache->save($bodyDigest, (string) $response->getBody(), $ttl);
     }
     array_unshift($entries, array($persistedRequest, $this->persistHeaders($response), $response->getStatusCode(), $bodyDigest, $currentTime + $ttl));
     $this->cache->save($key, serialize($entries));
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:35,代码来源:DefaultCacheStorage.php

示例6: validateResponse

 /**
  * Validate the HTTP response and throw exceptions on errors
  *
  * @throws ServerException
  */
 private function validateResponse()
 {
     if ($this->httpResponse->getStatusCode() !== 200) {
         $statusCode = $this->httpResponse->getStatusCode();
         throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
     } else {
         if (strpos($this->httpResponse->getHeader('Content-Type'), 'application/json') === false) {
             throw new ServerException('Server did not respond with the expected content-type (application/json)');
         }
     }
     try {
         $this->httpResponse->json();
     } catch (RuntimeException $e) {
         throw new ServerException($e->getMessage());
     }
 }
开发者ID:nexxome,项目名称:html-validator,代码行数:21,代码来源:Response.php

示例7: parseHeaders

 /**
  * Parses additional exception information from the response headers
  *
  * @param RequestInterface $request  Request that was issued
  * @param Response         $response The response from the request
  * @param array            $data     The current set of exception data
  */
 protected function parseHeaders(RequestInterface $request, Response $response, array &$data)
 {
     $data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
     if ($requestId = $response->getHeader('x-amz-request-id')) {
         $data['request_id'] = $requestId;
         $data['message'] .= " (Request-ID: {$requestId})";
     }
 }
开发者ID:skinnard,项目名称:FTL-2,代码行数:15,代码来源:DefaultXmlExceptionParser.php

示例8: decode

 public static function decode(Response $response)
 {
     if (strpos($response->getHeader(Header::CONTENT_TYPE), Mime::JSON) !== false) {
         $string = (string) $response->getBody();
         $response = json_decode($string);
         self::checkJsonError($string);
         return $response;
     }
 }
开发者ID:etaoins,项目名称:php-opencloud,代码行数:9,代码来源:Formatter.php

示例9: getDelay

 /**
  * {@inheritdoc}
  */
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         // Validate the checksum against our computed checksum
         if ($checksum = (string) $response->getHeader('x-amz-crc32')) {
             // Retry the request if the checksums don't match, otherwise, return null
             return $checksum != hexdec(Stream::getHash($response->getBody(), 'crc32b')) ? true : null;
         }
     }
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:13,代码来源:Crc32ErrorChecker.php

示例10: getDelay

 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         //Short circuit the rest of the checks if it was successful
         if ($response->isSuccessful()) {
             return false;
         } else {
             if (isset($this->errorCodes[$response->getStatusCode()])) {
                 if ($response->getHeader("Retry-After")) {
                     return $response->getHeader("Retry-After")->__toString();
                 } else {
                     return self::$defaultRetryAfter;
                 }
             } else {
                 return null;
             }
         }
     }
 }
开发者ID:keboola,项目名称:provisioning-client,代码行数:19,代码来源:MaintenanceBackoffStrategy.php

示例11: parse

 /**
  * {@inheritdoc}
  */
 public function parse(Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null);
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = $json;
         $json = array_change_key_case($json);
         $data = $this->doParse($data, $json);
     }
     return $data;
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:13,代码来源:AbstractJsonExceptionParser.php

示例12: getContextFromResponse

 private function getContextFromResponse(Response $response)
 {
     $extraFields = array();
     $headersToLookFor = array('x-served-by', 'x-backend', 'x-location', 'x-varnish');
     foreach ($headersToLookFor as $headerName) {
         if ($response->hasHeader($headerName)) {
             $extraFields[$headerName] = (string) $response->getHeader($headerName);
         }
     }
     return $extraFields;
 }
开发者ID:robertpisano,项目名称:LeeLee,代码行数:11,代码来源:MonologGuzzleLogAdapter.php

示例13: factory

 public static function factory(RequestInterface $request, Response $response)
 {
     $label = 'Bearer error response';
     $bearerReason = self::headerToReason($response->getHeader("WWW-Authenticate"));
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[bearer reason] ' . $bearerReason, '[url] ' . $request->getUrl()));
     $e = new static($message);
     $e->setResponse($response);
     $e->setRequest($request);
     $e->setBearerReason($bearerReason);
     return $e;
 }
开发者ID:Farik2605,项目名称:tobi,代码行数:11,代码来源:BearerErrorResponseException.php

示例14: getBackoffPeriod

 /**
  * Get the amount of time to delay in seconds before retrying a request
  *
  * @param int              $retries  Number of retries of the request
  * @param RequestInterface $request  Request that was sent
  * @param Response         $response Response that was received. Note that there may not be a response
  * @param HttpException    $e        Exception that was encountered if any
  *
  * @return bool|int Returns false to not retry or the number of seconds to delay between retries
  */
 public function getBackoffPeriod($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if (!$response) {
         return false;
     }
     if ($response->getStatusCode() != 429) {
         return false;
     }
     $reset = (string) $response->getHeader('X-Rate-Limit-Reset');
     if (!preg_match('/^[0-9]+$/', $reset)) {
         return false;
     }
     return ((int) $reset + 0.1) * $this->getMultiplier();
 }
开发者ID:dh-open,项目名称:desk-php,代码行数:24,代码来源:Strategy.php

示例15: doParse

 /**
  * {@inheritdoc}
  */
 protected function doParse(array $data, Response $response)
 {
     // Merge in error data from the JSON body
     if ($json = $data['parsed']) {
         $data = array_replace($data, $json);
     }
     // Correct error type from services like Amazon Glacier
     if (!empty($data['type'])) {
         $data['type'] = strtolower($data['type']);
     }
     // Retrieve the error code from services like Amazon Elastic Transcoder
     if ($code = (string) $response->getHeader('x-amzn-ErrorType')) {
         $data['code'] = substr($code, 0, strpos($code, ':'));
     }
     return $data;
 }
开发者ID:ebeauchamps,项目名称:brilliantretail,代码行数:19,代码来源:JsonRestExceptionParser.php


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