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


PHP RequestInterface::withHeader方法代码示例

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


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

示例1: fetchResumeUri

 private function fetchResumeUri()
 {
     $result = null;
     $body = $this->request->getBody();
     if ($body) {
         $headers = array('content-type' => 'application/json; charset=UTF-8', 'content-length' => $body->getSize(), 'x-upload-content-type' => $this->mimeType, 'x-upload-content-length' => $this->size, 'expect' => '');
         foreach ($headers as $key => $value) {
             $this->request = $this->request->withHeader($key, $value);
         }
     }
     $response = $this->client->execute($this->request, false);
     $location = $response->getHeaderLine('location');
     $code = $response->getStatusCode();
     if (200 == $code && true == $location) {
         return $location;
     }
     $message = $code;
     $body = json_decode((string) $this->request->getBody(), true);
     if (isset($body['error']['errors'])) {
         $message .= ': ';
         foreach ($body['error']['errors'] as $error) {
             $message .= "{$error[domain]}, {$error[message]};";
         }
         $message = rtrim($message, ';');
     }
     $error = "Failed to start the resumable upload (HTTP {$message})";
     $this->client->getLogger()->error($error);
     throw new GoogleException($error);
 }
开发者ID:Devids,项目名称:google-api-php-client,代码行数:29,代码来源:MediaFileUpload.php

示例2: sign

 /**
  * @param \Psr\Http\Message\RequestInterface $request
  *
  * @return \Psr\Http\Message\RequestInterface
  */
 public function sign(RequestInterface $request)
 {
     $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp();
     $data = implode('|', [$request->getMethod(), rtrim((string) $request->getUri(), '/'), $timestamp]);
     $signature = $this->signer->sign($data);
     return $request->withHeader(self::TIMESTAMP_HEADER, $timestamp)->withHeader(self::SIGNATURE_HEADER, $signature);
 }
开发者ID:livetyping,项目名称:hermitage-php-client,代码行数:12,代码来源:RequestSigner.php

示例3: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // TODO: add error handling
     // TODO: support other grant types?
     $accessToken = $this->provider->getAccessToken('client_credentials');
     return $request->withHeader('Authorization', 'Bearer ' . $accessToken);
 }
开发者ID:godmodelabs,项目名称:flora-client-php-auth,代码行数:10,代码来源:OAuth2.php

示例4: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // TODO: generate better nonce?
     $nonce = substr(md5(uniqid(uniqid() . '_', true)), 0, 16);
     $created = date('c');
     $digest = base64_encode(sha1(base64_decode($nonce) . $created . $this->password, true));
     $wsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->username, $digest, $nonce, $created);
     return $request->withHeader('Authorization', 'WSSE profile="UsernameToken"')->withHeader('X-WSSE', $wsse);
 }
开发者ID:php-http,项目名称:message,代码行数:12,代码来源:Wsse.php

示例5: onRequest

 /**
  *
  * @param RequestInterface $request
  */
 public function onRequest(RequestInterface $request)
 {
     reset($this->headers);
     $newRequest = $request->withHeader('Host', $request->getUri()->getHost())->withHeader('User-Agent', self::USER_AGENT);
     $addHeaders = function (&$array, RequestInterface $request, callable $callback) {
         $item = each($array);
         if (!$item) {
             return $request;
         }
         return $callback($array, $request, $callback)->withHeader($item['key'], $item['value']);
     };
     return $addHeaders($this->headers, $newRequest, $addHeaders);
 }
开发者ID:softrog,项目名称:gloo-client,代码行数:17,代码来源:HeaderMiddleware.php

示例6: __invoke

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 public function __invoke(RequestInterface $request)
 {
     $uri = $request->getUri();
     $path = $uri->getPath();
     $path .= $uri->getQuery() != null ? '?' . $uri->getQuery() : '';
     $payload = ['key' => 'master', 'exp' => time() + $this->exp, 'method' => $request->getMethod(), 'path' => $path];
     if (in_array($request->getMethod(), ['PUT', 'POST'])) {
         $body = $request->getBody();
         $computedHash = \GuzzleHttp\Psr7\hash($body, 'sha256');
         $payload['body'] = ['alg' => 'sha256', 'hash' => $computedHash];
     }
     $jws = new JWS(['typ' => 'JWT', 'alg' => 'HS256']);
     $jws->setPayload($payload)->sign($this->secret);
     $token = $jws->getTokenString();
     return $request->withHeader('Authorization', 'JWT token="' . $token . '"');
 }
开发者ID:caxy,项目名称:badgekit-client,代码行数:21,代码来源:JwtMiddleware.php

示例7: addHeaderToRequest

 /**
  * @param string $header
  * @param string|string[] $value
  */
 public function addHeaderToRequest($header, $value)
 {
     $this->request = $this->request->withHeader($header, $value);
 }
开发者ID:jacmoe,项目名称:php-workshop,代码行数:8,代码来源:CgiExecuteEvent.php

示例8: withHeader

 public function withHeader($name, $value)
 {
     $new = clone $this;
     $new->request = $this->request->withHeader($name, $value);
     return $new;
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:6,代码来源:Request.php

示例9: __construct

 /**
  * @since 2.0.0
  * @param string $dsn Data Source Name
  */
 public function __construct($dsn)
 {
     $this->driver = new CurlDriver();
     $this->request = new Request($dsn);
     $this->request->withHeader('Content-Type', 'application/json');
 }
开发者ID:jpcsupplies,项目名称:bitcoind-php,代码行数:10,代码来源:Client.php

示例10: applyRequest

 /**
  * {@inheritdoc}
  */
 public function applyRequest(HttpRequestInterface $request, array $options)
 {
     return $request->withHeader('Accept-Encoding', 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3')->withHeader('Content-Type', 'application/json');
 }
开发者ID:yashb,项目名称:generator,代码行数:7,代码来源:RequestHeaderMiddleware.php

示例11: handleRequest

 /**
  * Add authentication data to the request and sends it. Calls handleResponse when done.
  *
  * @param RequestInterface $request
  *
  * @return mixed
  */
 protected function handleRequest(RequestInterface $request, array $requestOptions = [])
 {
     $request->withHeader('Authorization', 'Bearer ' . $this->options['token']);
     try {
         $response = $this->httpClient->send($request);
     } catch (ClientException $ex) {
         return $this->handleResponse($ex->getResponse());
     }
     return $this->handleResponse($response, $requestOptions);
 }
开发者ID:eresults,项目名称:unity-php-api,代码行数:17,代码来源:Client.php

示例12: withHeader

 /**
  * @param string $header
  * @param string|\string[] $value
  * @return \Psr\Http\Message\MessageInterface
  */
 public function withHeader($header, $value)
 {
     $this->request = $this->request->withHeader($header, $value);
     return $this;
 }
开发者ID:bweston92,项目名称:expressive-async,代码行数:10,代码来源:ServerRequest.php

示例13: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     $header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password)));
     return $request->withHeader('Authorization', $header);
 }
开发者ID:php-http,项目名称:message,代码行数:8,代码来源:BasicAuth.php

示例14: __invoke

 /**
  * Add HTTP header to request.
  *
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $next)
 {
     return call_user_func($next, $request->withHeader(self::HEADER, $this->key), $response);
 }
开发者ID:Teknologica,项目名称:rebilly-php,代码行数:9,代码来源:ApiKeyAuthentication.php

示例15: __invoke

 public function __invoke(RequestInterface $request, array $options)
 {
     $fn = $this->nextHandler;
     if (!isset($options['oxygen_site']) || !$options['oxygen_site'] instanceof Site) {
         throw new \RuntimeException(sprintf('The option "oxygen_site" is expected to contain an instance of %s.', Site::class));
     }
     if (!isset($options['oxygen_action']) || !$options['oxygen_action'] instanceof ActionInterface) {
         throw new \RuntimeException(sprintf('The option "oxygen_action" is expected to contain an instance of %s.', ActionInterface::class));
     }
     $transferInfo = $previousCallable = null;
     if (isset($options['on_stats'])) {
         $previousCallable = $options['on_stats'];
     }
     $options['on_stats'] = function (TransferStats $stats) use(&$transferInfo, $previousCallable) {
         $transferInfo = new TransferInfo($stats->getHandlerStats());
         if ($previousCallable) {
             /* @var callable $previousCallable */
             $previousCallable($stats);
         }
     };
     /** @var Site $site */
     $site = $options['oxygen_site'];
     /** @var ActionInterface $action */
     $action = $options['oxygen_action'];
     $options['request_id'] = $requestId = \Undine\Functions\generate_uuid();
     // Kind of like str_rot8, for hexadecimal strings.
     $responseId = strtr($requestId, 'abcdef0123456789', '23456789abcdef01');
     $expiresAt = time() + 86400;
     $userName = '';
     $stateParameters = $this->stateTracker->getParameters($site);
     $requestData = ['oxygenRequestId' => $requestId, 'requestExpiresAt' => $expiresAt, 'publicKey' => $site->getPublicKey(), 'signature' => \Undine\Functions\openssl_sign_data($site->getPrivateKey(), sprintf('%s|%d', $requestId, $expiresAt)), 'handshakeKey' => $this->handshakeKeyName, 'handshakeSignature' => \Undine\Functions\openssl_sign_data($this->handshakeKeyValue, $this->getUrlSlug($site->getUrl())), 'version' => $this->moduleVersion, 'baseUrl' => (string) $site->getUrl(), 'actionName' => $action->getName(), 'actionParameters' => $action->getParameters(), 'userName' => $userName, 'userId' => $site->getUser()->getId(), 'stateParameters' => $stateParameters];
     $oxygenRequest = $request->withHeader('accept', 'text/html,application/json,application/oxygen')->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($requestData)));
     if ($site->hasHttpCredentials()) {
         $oxygenRequest = $oxygenRequest->withHeader('Authorization', 'Basic ' . base64_encode(sprintf('%s:%s', $site->getHttpCredentials()->getUsername(), $site->getHttpCredentials()->getPassword())));
     }
     return $fn($oxygenRequest, $options)->then(function (ResponseInterface $response) use($site, $request, $options, &$transferInfo, $responseId, $action) {
         $responseData = $this->extractData($responseId, $request, $options, $response, $transferInfo);
         try {
             $reaction = $this->createReaction($action, $responseData);
         } catch (ExceptionInterface $e) {
             throw new ResponseException(ResponseException::ACTION_RESULT_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         try {
             $this->stateTracker->setResult($site, $responseData['stateResult']);
         } catch (\Exception $e) {
             throw new ResponseException(ResponseException::STATE_MALFORMED, $request, $options, $response, $transferInfo, $e);
         }
         return $reaction;
     }, function (RequestException $e) use($options, &$transferInfo) {
         throw new NetworkException($e->getHandlerContext()['errno'], $e->getRequest(), $options, $e->getResponse(), $transferInfo);
     })->otherwise(function (\Exception $exception) use($site) {
         $this->stateTracker->setException($site, $exception);
         throw $exception;
     });
 }
开发者ID:Briareos,项目名称:Undine,代码行数:55,代码来源:OxygenProtocolMiddleware.php


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