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


PHP RequestInterface::getHeader方法代码示例

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


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

示例1: signRequest

 /**
  * @param RequestInterface|EntityEnclosingRequestInterface $request
  * @param Credentials $credentials
  */
 public function signRequest($request, $credentials)
 {
     $request->setHeader('X-HMB-Signature-Method', self::DEFAULT_METHOD);
     $request->setHeader('X-HMB-Signature-Version', self::DEFAULT_SIGN_VERSION);
     $request->setHeader('X-HMB-TimeStamp', time());
     $contentMd5 = $request instanceof EntityEnclosingRequestInterface ? md5($request->getBody()) : '';
     if ($contentMd5) {
         $request->setHeader('Content-MD5', $contentMd5);
     }
     $sign = array();
     $sign[] = strtoupper($request->getMethod());
     $sign[] = $request->getHost();
     if ($request->getHeader('Content-MD5')) {
         $sign[] = $request->getHeader('Content-MD5');
     }
     if ($request->getHeader('Content-Type')) {
         $sign[] = $request->getHeader('Content-Type');
     }
     $sign[] = $request->getHeader('X-HMB-Signature-Method');
     $sign[] = $request->getHeader('X-HMB-Signature-Version');
     $sign[] = $request->getHeader('X-HMB-TimeStamp');
     if ($request->getHeader('X-HMB-User-Session-Token')) {
         $sign[] = $request->getHeader('X-HMB-User-Session-Token');
     }
     $sign[] = $request->getQuery(true) ? $request->getPath() . '?' . $request->getQuery(true) : $request->getPath();
     $signature = base64_encode(hash_hmac(strtolower($request->getHeader('X-HMB-Signature-Method')), implode("\n", $sign), $credentials->getSecret()));
     $request->setHeader('Authorization', sprintf('%s %s:%s', self::AUTHORIZATION_SCHME, $credentials->getKey(), $signature));
 }
开发者ID:sonicmoov,项目名称:hmb-sdk-php,代码行数:32,代码来源:Signature.php

示例2: handshake

 /**
  * @param Guzzle\Http\Message\RequestInterface
  * @return Guzzle\Http\Message\Response
  */
 public function handshake(RequestInterface $request)
 {
     $body = $this->sign($request->getHeader('Sec-WebSocket-Key1', true), $request->getHeader('Sec-WebSocket-Key2', true), (string) $request->getBody());
     $headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => $request->getHeader('Origin', true), 'Sec-WebSocket-Location' => 'ws://' . $request->getHeader('Host', true) . $request->getPath());
     $response = new Response(101, $headers, $body);
     $response->setStatus(101, 'WebSocket Protocol Handshake');
     return $response;
 }
开发者ID:unkerror,项目名称:Budabot,代码行数:12,代码来源:Hixie76.php

示例3: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Add a date header if one is not set
     if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
         $request->setHeader('Date', gmdate(DateFormat::RFC2822));
     }
     $stringToSign = (string) $request->getHeader('Date') ?: (string) $request->getHeader('x-amz-date');
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     $request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
 }
开发者ID:risyasin,项目名称:webpagetest,代码行数:13,代码来源:CloudFrontSignature.php

示例4: createCanonicalizedString

 /**
  * {@inheritdoc}
  */
 public function createCanonicalizedString(RequestInterface $request, $expires = null)
 {
     $buffer = $request->getMethod() . "\n";
     // Add the interesting headers
     foreach ($this->signableHeaders as $header) {
         $buffer .= (string) $request->getHeader($header) . "\n";
     }
     // Choose dates from left to right based on what's set
     $date = $expires ?: (string) $request->getHeader('date');
     $buffer .= "{$date}\n" . $this->createCanonicalizedAmzHeaders($request) . $this->createCanonicalizedResource($request);
     return $buffer;
 }
开发者ID:noahkim,项目名称:kowop,代码行数:15,代码来源:S3Signature.php

示例5: handshake

 /**
  * @param  \Guzzle\Http\Message\RequestInterface $request
  * @return \Guzzle\Http\Message\Response
  * @throws \UnderflowException If there hasn't been enough data received
  */
 public function handshake(RequestInterface $request)
 {
     $body = substr($request->getBody(), 0, 8);
     if (8 !== strlen($body)) {
         throw new \UnderflowException("Not enough data received to issue challenge response");
     }
     $challenge = $this->sign((string) $request->getHeader('Sec-WebSocket-Key1'), (string) $request->getHeader('Sec-WebSocket-Key2'), $body);
     $headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => (string) $request->getHeader('Origin'), 'Sec-WebSocket-Location' => 'ws://' . (string) $request->getHeader('Host') . $request->getPath());
     $response = new Response(101, $headers, $challenge);
     $response->setStatus(101, 'WebSocket Protocol Handshake');
     return $response;
 }
开发者ID:DannyHuisman,项目名称:Ratchet,代码行数:17,代码来源:Hixie76.php

示例6: verifyAll

 /**
  * Given an array of the headers this method will run through all verification methods
  * @param \Guzzle\Http\Message\RequestInterface $request
  * @return bool TRUE if all headers are valid, FALSE if 1 or more were invalid
  */
 public function verifyAll(RequestInterface $request)
 {
     $passes = 0;
     $passes += (int) $this->verifyMethod($request->getMethod());
     $passes += (int) $this->verifyHTTPVersion($request->getProtocolVersion());
     $passes += (int) $this->verifyRequestURI($request->getPath());
     $passes += (int) $this->verifyHost((string) $request->getHeader('Host'));
     $passes += (int) $this->verifyUpgradeRequest((string) $request->getHeader('Upgrade'));
     $passes += (int) $this->verifyConnection((string) $request->getHeader('Connection'));
     $passes += (int) $this->verifyKey((string) $request->getHeader('Sec-WebSocket-Key'));
     //$passes += (int)$this->verifyVersion($headers['Sec-WebSocket-Version']); // Temporarily breaking functionality
     return 7 === $passes;
 }
开发者ID:hughnguy,项目名称:php,代码行数:18,代码来源:HandshakeVerifier.php

示例7: shouldRevalidate

 public function shouldRevalidate(RequestInterface $request, Response $response)
 {
     if ($request->getMethod() != RequestInterface::GET) {
         return false;
     }
     $reqCache = $request->getHeader('Cache-Control');
     $resCache = $response->getHeader('Cache-Control');
     $revalidate = $request->getHeader('Pragma') == 'no-cache' || $reqCache && ($reqCache->hasDirective('no-cache') || $reqCache->hasDirective('must-revalidate')) || $resCache && ($resCache->hasDirective('no-cache') || $resCache->hasDirective('must-revalidate'));
     if (!$revalidate && !$resCache && $response->hasHeader('ETag')) {
         $revalidate = true;
     }
     return $revalidate;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:13,代码来源:DefaultRevalidation.php

示例8: onOpen

 /**
  * {@inheritdoc}
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     $header = (string) $request->getHeader('Origin');
     $origin = parse_url($header, PHP_URL_HOST) ?: $header;
     if (!in_array($origin, $this->allowedOrigins)) {
         return $this->close($conn, 403);
     }
     return $this->_component->onOpen($conn, $request);
 }
开发者ID:DannyHuisman,项目名称:Ratchet,代码行数:12,代码来源:OriginCheck.php

示例9: signRequest

 /**
  * {@inheritdoc}
  */
 public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // Add a date header if one is not set
     if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
         $request->setHeader('Date', $this->getDateTime(DateFormat::RFC1123));
     }
     // Add the security token if one is present
     if ($credentials->getSecurityToken()) {
         $request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
     }
     // Determine the string to sign
     $stringToSign = $request->getHeader('Date', true) ?: $request->getHeader('x-amz-date', true);
     $request->getParams()->set('aws.string_to_sign', $stringToSign);
     // Calculate the signature
     $signature = base64_encode(hash_hmac('sha256', $stringToSign, $credentials->getSecretKey(), true));
     // Add the authorization header to the request
     $headerFormat = 'AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s';
     $request->setHeader('X-Amzn-Authorization', sprintf($headerFormat, $credentials->getAccessKeyId(), $signature));
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:22,代码来源:SignatureV3Https.php

示例10: canCacheRequest

 public function canCacheRequest(RequestInterface $request)
 {
     if ($request->getMethod() != RequestInterface::GET && $request->getMethod() != RequestInterface::HEAD) {
         return false;
     }
     if ($request->hasHeader('Cache-Control') && $request->getHeader('Cache-Control')->hasDirective('no-store')) {
         return false;
     }
     return true;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:10,代码来源:DefaultCanCacheStrategy.php

示例11: onOpen

 /**
  * {@inheritdoc}
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     $header = (string) $request->getHeader('Origin');
     $origin = parse_url($header, PHP_URL_HOST) ?: $header;
     if (!in_array($origin, $this->allowedOrigins)) {
         $this->eventDispatcher->dispatch(Events::CLIENT_REJECTED, new ClientRejectedEvent($origin, $request));
         return $this->close($conn, 403);
     }
     return $this->_component->onOpen($conn, $request);
 }
开发者ID:rsrodrig,项目名称:MeetMeSoftware,代码行数:13,代码来源:OriginCheck.php

示例12: getParamsToSign

 public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
 {
     $params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_version' => $this->config['version']));
     // Filter out oauth_token during temp token step, as in request_token.
     if ($this->config['token'] !== false) {
         $params->add('oauth_token', $this->config['token']);
     }
     // Add call back uri
     if (isset($this->config['callback_uri']) && !empty($this->config['callback_uri'])) {
         $params->add('oauth_callback', $this->config['callback_uri']);
     }
     // Add query string parameters
     $params->merge($request->getQuery());
     // Add POST fields to signing string
     if (!$this->config->get('disable_post_params') && $request instanceof EntityEnclosingRequestInterface && false !== strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded')) {
         $params->merge($request->getPostFields());
     }
     // Sort params
     $params = $params->getAll();
     ksort($params);
     return $params;
 }
开发者ID:vdmi,项目名称:guzzle-oauth,代码行数:22,代码来源:OauthPlugin.php

示例13: factory

 /**
  * Factory method to create a new curl handle based on an HTTP request.
  *
  * There are some helpful options you can set to enable specific behavior:
  * - debug:    Set to true to enable cURL debug functionality to track the actual headers sent over the wire.
  * - progress: Set to true to enable progress function callbacks.
  *
  * @param RequestInterface $request Request
  *
  * @return CurlHandle
  * @throws RuntimeException
  */
 public static function factory(RequestInterface $request)
 {
     $requestCurlOptions = $request->getCurlOptions();
     $mediator = new RequestMediator($request, $requestCurlOptions->get('emit_io'));
     $tempContentLength = null;
     $method = $request->getMethod();
     $bodyAsString = $requestCurlOptions->get(self::BODY_AS_STRING);
     // Prepare url
     $url = (string) $request->getUrl();
     if (($pos = strpos($url, '#')) !== false) {
         // strip fragment from url
         $url = substr($url, 0, $pos);
     }
     // Array of default cURL options.
     $curlOptions = array(CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_PORT => $request->getPort(), CURLOPT_HTTPHEADER => array(), CURLOPT_WRITEFUNCTION => array($mediator, 'writeResponseBody'), CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'), CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2);
     if (defined('CURLOPT_PROTOCOLS')) {
         // Allow only HTTP and HTTPS protocols
         $curlOptions[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
     }
     // Add CURLOPT_ENCODING if Accept-Encoding header is provided
     if ($acceptEncodingHeader = $request->getHeader('Accept-Encoding')) {
         $curlOptions[CURLOPT_ENCODING] = (string) $acceptEncodingHeader;
         // Let cURL set the Accept-Encoding header, prevents duplicate values
         $request->removeHeader('Accept-Encoding');
     }
     // Enable curl debug information if the 'debug' param was set
     if ($requestCurlOptions->get('debug')) {
         $curlOptions[CURLOPT_STDERR] = fopen('php://temp', 'r+');
         // @codeCoverageIgnoreStart
         if (false === $curlOptions[CURLOPT_STDERR]) {
             throw new RuntimeException('Unable to create a stream for CURLOPT_STDERR');
         }
         // @codeCoverageIgnoreEnd
         $curlOptions[CURLOPT_VERBOSE] = true;
     }
     // Specify settings according to the HTTP method
     if ($method == 'GET') {
         $curlOptions[CURLOPT_HTTPGET] = true;
     } elseif ($method == 'HEAD') {
         $curlOptions[CURLOPT_NOBODY] = true;
         // HEAD requests do not use a write function
         unset($curlOptions[CURLOPT_WRITEFUNCTION]);
     } elseif (!$request instanceof EntityEnclosingRequest) {
         $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
     } else {
         $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
         // Handle sending raw bodies in a request
         if ($request->getBody()) {
             // You can send the body as a string using curl's CURLOPT_POSTFIELDS
             if ($bodyAsString) {
                 $curlOptions[CURLOPT_POSTFIELDS] = (string) $request->getBody();
                 // Allow curl to add the Content-Length for us to account for the times when
                 // POST redirects are followed by GET requests
                 if ($tempContentLength = $request->getHeader('Content-Length')) {
                     $tempContentLength = (int) (string) $tempContentLength;
                 }
                 // Remove the curl generated Content-Type header if none was set manually
                 if (!$request->hasHeader('Content-Type')) {
                     $curlOptions[CURLOPT_HTTPHEADER][] = 'Content-Type:';
                 }
             } else {
                 $curlOptions[CURLOPT_UPLOAD] = true;
                 // Let cURL handle setting the Content-Length header
                 if ($tempContentLength = $request->getHeader('Content-Length')) {
                     $tempContentLength = (int) (string) $tempContentLength;
                     $curlOptions[CURLOPT_INFILESIZE] = $tempContentLength;
                 }
                 // Add a callback for curl to read data to send with the request only if a body was specified
                 $curlOptions[CURLOPT_READFUNCTION] = array($mediator, 'readRequestBody');
                 // Attempt to seek to the start of the stream
                 $request->getBody()->seek(0);
             }
         } else {
             // Special handling for POST specific fields and files
             $postFields = false;
             if (count($request->getPostFiles())) {
                 $postFields = $request->getPostFields()->useUrlEncoding(false)->urlEncode();
                 foreach ($request->getPostFiles() as $key => $data) {
                     $prefixKeys = count($data) > 1;
                     foreach ($data as $index => $file) {
                         // Allow multiple files in the same key
                         $fieldKey = $prefixKeys ? "{$key}[{$index}]" : $key;
                         $postFields[$fieldKey] = $file->getCurlValue();
                     }
                 }
             } elseif (count($request->getPostFields())) {
                 $postFields = (string) $request->getPostFields()->useUrlEncoding(true);
             }
//.........这里部分代码省略.........
开发者ID:TechArea,项目名称:core,代码行数:101,代码来源:CurlHandle.php

示例14: isProtocol

 /**
  * {@inheritdoc}
  */
 public function isProtocol(RequestInterface $request)
 {
     $version = (int) $request->getHeader('Sec-WebSocket-Version', -1);
     return $this->getVersionNumber() === $version;
 }
开发者ID:unkerror,项目名称:Budabot,代码行数:8,代码来源:RFC6455.php

示例15: createPresignedRequest

 private function createPresignedRequest(RequestInterface $request, CredentialsInterface $credentials)
 {
     // POST requests can be sent as GET requests instead by moving the
     // POST fields into the query string.
     if ($request instanceof EntityEnclosingRequestInterface && $request->getMethod() === 'POST' && strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === 0) {
         $sr = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
         // Move POST fields to the query if they are present
         foreach ($request->getPostFields() as $name => $value) {
             $sr->getQuery()->set($name, $value);
         }
     } else {
         $sr = clone $request;
     }
     // Make sure to handle temporary credentials
     if ($token = $credentials->getSecurityToken()) {
         $sr->setHeader('X-Amz-Security-Token', $token);
         $sr->getQuery()->set('X-Amz-Security-Token', $token);
     }
     $this->moveHeadersToQuery($sr);
     return $sr;
 }
开发者ID:elephantcode,项目名称:elephantcode,代码行数:21,代码来源:SignatureV4.php


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