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


PHP RequestInterface::hasHeader方法代码示例

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


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

示例1: getRequestId

 /**
  * @return string
  */
 public function getRequestId()
 {
     if ($this->request->hasHeader($this->headerName)) {
         return $this->request->getHeader($this->headerName);
     }
     return $this->fallback->getRequestId();
 }
开发者ID:arkitekto,项目名称:request-id,代码行数:10,代码来源:ExtractsRequestIdFromHeader.php

示例2: getHeader

 /**
  * {@inheritdoc}
  */
 public function getHeader($header)
 {
     if (!$this->request->hasHeader($header)) {
         if (strtolower($header) === 'host' && ($this->request->getUri() && $this->request->getUri()->getHost())) {
             return array($this->getHostFromUri());
         }
         return array();
     }
     return $this->request->getHeader($header);
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:13,代码来源:Request.php

示例3: theSentRequestShouldContainAnHeader

 /**
  * @Then the sent request should contain an :header header
  */
 public function theSentRequestShouldContainAnHeader($header)
 {
     if (null === $this->request) {
         throw new \RuntimeException('No request found, maybe no registered hook, right?');
     } else {
         if (!$this->request->hasHeader($header)) {
             throw new \RuntimeException('Header not found in request');
         }
     }
 }
开发者ID:sroze,项目名称:tolerance,代码行数:13,代码来源:GuzzleContext.php

示例4: addExpectHeader

 private function addExpectHeader(RequestInterface $request, array $options, array &$modify)
 {
     // Determine if the Expect header should be used
     if ($request->hasHeader('Expect')) {
         return;
     }
     $expect = isset($options['expect']) ? $options['expect'] : null;
     // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
     if ($expect === false || $request->getProtocolVersion() < 1.1) {
         return;
     }
     // The expect header is unconditionally enabled
     if ($expect === true) {
         $modify['set_headers']['Expect'] = '100-Continue';
         return;
     }
     // By default, send the expect header when the payload is > 1mb
     if ($expect === null) {
         $expect = 1048576;
     }
     // Always add if the body cannot be rewound, the size cannot be
     // determined, or the size is greater than the cutoff threshold
     $body = $request->getBody();
     $size = $body->getSize();
     if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
         $modify['set_headers']['Expect'] = '100-Continue';
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:PrepareBodyMiddleware.php

示例5: match

 /**
  * @param RequestInterface $request
  * @return MatchResultInterface
  */
 public function match(RequestInterface $request)
 {
     if ($request->hasHeader('X-GitHub-Event')) {
         return new MatchResult(true, $this->getNotificationEvent($request));
     }
     return new UnmatchedResult();
 }
开发者ID:jeremygiberson,项目名称:psr7-push-notification-middleware,代码行数:11,代码来源:Github.php

示例6: presign

 /**
  * Always add a x-amz-content-sha-256 for data integrity.
  */
 public function presign(RequestInterface $request, CredentialsInterface $credentials, $expires)
 {
     if (!$request->hasHeader('x-amz-content-sha256')) {
         $request = $request->withHeader('X-Amz-Content-Sha256', $this->getPresignedPayload($request));
     }
     return parent::presign($request, $credentials, $expires);
 }
开发者ID:Air-Craft,项目名称:air-craft-www,代码行数:10,代码来源:S3SignatureV4.php

示例7: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request, callable $next, callable $first)
 {
     foreach ($this->headers as $header) {
         if ($request->hasHeader($header)) {
             $request = $request->withoutHeader($header);
         }
     }
     return $next($request);
 }
开发者ID:php-http,项目名称:plugins,代码行数:12,代码来源:HeaderRemovePlugin.php

示例8: __invoke

 public function __invoke(CommandInterface $command, RequestInterface $request)
 {
     $name = $command->getName();
     $body = $request->getBody();
     if (!$request->hasHeader('Content-MD5') && $body->getSize() && in_array($name, self::$requireMd5)) {
         $request = $request->withHeader('Content-MD5', base64_encode(Psr7\hash($body, 'md5', true)));
     }
     $next = $this->nextHandler;
     return $next($command, $request);
 }
开发者ID:HaareeKrishna,项目名称:CommunityCloud,代码行数:10,代码来源:ApplyMd5Middleware.php

示例9: normalizeCustomHeaders

 /**
  * Normalizes the custom headers for signing.
  *
  * @return string[]
  *   An array of normalized headers.
  */
 protected function normalizeCustomHeaders()
 {
     $headers = [];
     // The spec requires that headers are sorted by header name.
     sort($this->headers);
     foreach ($this->headers as $header) {
         if ($this->request->hasHeader($header)) {
             $headers[] = strtolower($header) . ':' . $this->request->getHeaderLine($header);
         }
     }
     return $headers;
 }
开发者ID:acquia,项目名称:http-hmac-php,代码行数:18,代码来源:AuthorizationHeaderBuilder.php

示例10: signRequest

 /**
  * Signs the request, adds the HMAC hash to the authorization header.
  *
  * @param \Psr\Http\Message\RequestInterface $request
  *
  * @return \Psr\Http\Message\RequestInterface
  */
 public function signRequest(RequestInterface $request)
 {
     if (!$request->hasHeader('Date')) {
         $time = new \DateTime();
         $time->setTimezone(new \DateTimeZone('GMT'));
         $request = $request->withHeader('Date', $time->format('D, d M Y H:i:s \\G\\M\\T'));
     }
     if (!$request->hasHeader('Content-Type')) {
         $request = $request->withHeader('Content-Type', $this->defaultContentType);
     }
     $authorization = $this->requestSigner->getAuthorization(new RequestWrapper($request), $this->id, $this->secretKey);
     return $request->withHeader('Authorization', $authorization);
 }
开发者ID:itafroma,项目名称:http-hmac-php,代码行数:20,代码来源:HmacAuthMiddleware.php

示例11: forgeServerGlobal

 /**
  * Take a request and update the $_SERVER global to match
  *
  * @param RequestInterface $request
  */
 private function forgeServerGlobal(RequestInterface $request)
 {
     $_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
     $_SERVER['REQUEST_METHOD'] = $request->getMethod();
     $_SERVER['QUERY_STRING'] = $request->getUri()->getQuery();
     if ($request->hasHeader('Content-Type')) {
         $_SERVER['CONTENT_TYPE'] = $request->getHeaderLine('Content-Type');
     }
     if ($request->hasHeader('Referer')) {
         $_SERVER['HTTP_REFERER'] = $request->getHeaderLine('Referer');
     }
     if ($request->hasHeader('X-Requested-with')) {
         $_SERVER['HTTP_X_REQUESTED_WITH'] = $request->getHeaderLine('X-Requested-With');
     }
     if ($request->hasHeader('User-Agent')) {
         $_SERVER['HTTP_USER_AGENT'] = $request->getHeaderLine('User-Agent');
     }
     if ($request->hasHeader('X-Forwarded-For')) {
         $_SERVER['HTTP_X_FORWARDED_FOR'] = $request->getHeaderLine('X-Forwarded-For');
     }
     return $this;
 }
开发者ID:liamja,项目名称:bunsen,代码行数:27,代码来源:TestCase.php

示例12: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request, callable $next, callable $first)
 {
     if (!$request->hasHeader('Content-Length')) {
         $stream = $request->getBody();
         // Cannot determine the size so we use a chunk stream
         if (null === $stream->getSize()) {
             $stream = new ChunkStream($stream);
             $request = $request->withBody($stream);
         } else {
             $request = $request->withHeader('Content-Length', $stream->getSize());
         }
     }
     return $next($request);
 }
开发者ID:xabbuh,项目名称:plugins,代码行数:17,代码来源:ContentLengthPlugin.php

示例13: __invoke

 public function __invoke(CommandInterface $command, RequestInterface $request)
 {
     $next = $this->nextHandler;
     $name = $command->getName();
     $body = $request->getBody();
     if (in_array($name, self::$md5) && !$request->hasHeader('Content-MD5')) {
         // Set the content MD5 header for operations that require it.
         $request = $request->withHeader('Content-MD5', base64_encode(Psr7\hash($body, 'md5', true)));
     } elseif (in_array($name, self::$sha256) && $command['ContentSHA256']) {
         // Set the content hash header if provided in the parameters.
         $request = $request->withHeader('X-Amz-Content-Sha256', $command['ContentSHA256']);
     }
     return $next($command, $request);
 }
开发者ID:Cinemacloud,项目名称:angular-moviemasher,代码行数:14,代码来源:ApplyChecksumMiddleware.php

示例14: getPayload

 protected function getPayload(RequestInterface $request)
 {
     // Calculate the request signature payload
     if ($request->hasHeader('X-Amz-Content-Sha256')) {
         // Handle streaming operations (e.g. Glacier.UploadArchive)
         return $request->getHeaderLine('X-Amz-Content-Sha256');
     }
     if (!$request->getBody()->isSeekable()) {
         throw new CouldNotCreateChecksumException('sha256');
     }
     try {
         return Psr7\hash($request->getBody(), 'sha256');
     } catch (\Exception $e) {
         throw new CouldNotCreateChecksumException('sha256', $e);
     }
 }
开发者ID:bradelement,项目名称:flash,代码行数:16,代码来源:SignatureV4.php

示例15: createFromRequest

 /**
  * {@inheritDoc}
  */
 public static function createFromRequest(RequestInterface $request)
 {
     if (!$request->hasHeader('Authorization')) {
         throw new MalformedRequestException('Authorization header is required.', null, 0, $request);
     }
     $header = $request->getHeaderLine('Authorization');
     $id_match = preg_match('/.*id="(.*?)"/', $header, $id_matches);
     $realm_match = preg_match('/.*realm="(.*?)"/', $header, $realm_matches);
     $nonce_match = preg_match('/.*nonce="(.*?)"/', $header, $nonce_matches);
     $version_match = preg_match('/.*version="(.*?)"/', $header, $version_matches);
     $signature_match = preg_match('/.*signature="(.*?)"/', $header, $signature_matches);
     $headers_match = preg_match('/.*headers="(.*?)"/', $header, $headers_matches);
     if (!$id_match || !$realm_match || !$nonce_match || !$version_match || !$signature_match) {
         throw new MalformedRequestException('Authorization header requires a realm, id, version, nonce and a signature.', null, 0, $request);
     }
     $customHeaders = !empty($headers_matches[1]) ? explode('%3B', $headers_matches[1]) : [];
     return new static(rawurldecode($realm_matches[1]), $id_matches[1], $nonce_matches[1], $version_matches[1], $customHeaders, $signature_matches[1]);
 }
开发者ID:acquia,项目名称:http-hmac-php,代码行数:21,代码来源:AuthorizationHeader.php


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