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


PHP RequestInterface::getHeaders方法代码示例

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


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

示例1: getDefaultOptions

 protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
 {
     $url = $request->getUrl();
     // Strip fragment from URL. See:
     // https://github.com/guzzle/guzzle/issues/453
     if (($pos = strpos($url, '#')) !== false) {
         $url = substr($url, 0, $pos);
     }
     $config = $request->getConfig();
     $options = array(CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => array($mediator, 'writeResponseBody'), CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'), CURLOPT_READFUNCTION => array($mediator, 'readRequestBody'), 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, '_headers' => $request->getHeaders());
     if (defined('CURLOPT_PROTOCOLS')) {
         // Allow only HTTP and HTTPS protocols
         $options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
     }
     // Add CURLOPT_ENCODING if Accept-Encoding header is provided
     if ($request->hasHeader('Accept-Encoding')) {
         $options[CURLOPT_ENCODING] = $request->getHeader('Accept-Encoding');
         // Let cURL set the Accept-Encoding header. Without this change
         // curl could add a duplicate value.
         $this->removeHeader('Accept-Encoding', $options);
     }
     // cURL sometimes adds a content-type by default. Prevent this.
     if (!$request->hasHeader('Content-Type')) {
         $options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
     }
     return $options;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:27,代码来源:CurlFactory.php

示例2: formatHeaders

 /**
  * @param RequestInterface|ResponseInterface $message
  * @return string
  */
 protected function formatHeaders($message)
 {
     $headers = [];
     foreach ($message->getHeaders() as $header => $value) {
         $headers[] = sprintf('%s: %s', $header, implode("\n  : ", $value));
     }
     return implode("\n", $headers);
 }
开发者ID:glooby,项目名称:debug-bundle,代码行数:12,代码来源:AbstractMessageFormatter.php

示例3: createRingRequest

 /**
  * Creates a Ring request from a request object.
  *
  * This function does not hook up the "then" and "progress" events that
  * would be required for actually sending a Guzzle request through a
  * RingPHP handler.
  *
  * @param RequestInterface $request Request to convert.
  *
  * @return array Converted Guzzle Ring request.
  */
 public static function createRingRequest(RequestInterface $request)
 {
     $options = $request->getConfig()->toArray();
     $url = $request->getUrl();
     // No need to calculate the query string twice (in URL and query).
     $qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
     return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:19,代码来源:RingBridge.php

示例4: getDefaultOptions

 protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
 {
     $url = $request->getUrl();
     // Strip fragment from URL. See:
     // https://github.com/guzzle/guzzle/issues/453
     if (($pos = strpos($url, '#')) !== false) {
         $url = substr($url, 0, $pos);
     }
     $config = $request->getConfig();
     $options = [CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => [$mediator, 'writeResponseBody'], CURLOPT_HEADERFUNCTION => [$mediator, 'receiveResponseHeader'], CURLOPT_READFUNCTION => [$mediator, 'readRequestBody'], 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, '_headers' => $request->getHeaders()];
     if (defined('CURLOPT_PROTOCOLS')) {
         // Allow only HTTP and HTTPS protocols
         $options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
     }
     // cURL sometimes adds a content-type by default. Prevent this.
     if (!$request->hasHeader('Content-Type')) {
         $options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
     }
     return $options;
 }
开发者ID:ChenOhayon,项目名称:sitepoint_codes,代码行数:20,代码来源:CurlFactory.php

示例5: getRequestHeaderAsString

 private function getRequestHeaderAsString(RequestInterface $request)
 {
     $message = vsprintf('%s %s HTTP/%s', [strtoupper($request->getMethod()), $request->getUrl(), $request->getProtocolVersion()]) . "\r\n";
     foreach ($request->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\r\n";
     }
     $message .= "\r\n";
     return $message;
 }
开发者ID:schmunk42,项目名称:docker-php,代码行数:9,代码来源:DockerAdapter.php

示例6: extractHeadersArgument

 /**
  * @param RequestInterface $request
  */
 protected function extractHeadersArgument(RequestInterface $request)
 {
     $url = Url::fromString($request->getUrl());
     foreach ($request->getHeaders() as $name => $header) {
         if ('host' === strtolower($name) && $header[0] === $url->getHost()) {
             continue;
         }
         if ('user-agent' === strtolower($name)) {
             $this->addOption('A', escapeshellarg($header[0]));
             continue;
         }
         foreach ((array) $header as $headerValue) {
             $this->addOption('H', escapeshellarg("{$name}: {$headerValue}"));
         }
     }
 }
开发者ID:mdrost,项目名称:cuzzle,代码行数:19,代码来源:CurlFormatter.php

示例7: getDefaultOptions

 private function getDefaultOptions(RequestInterface $request)
 {
     $headers = '';
     foreach ($request->getHeaders() as $name => $values) {
         $headers .= $name . ': ' . implode(', ', $values) . "\r\n";
     }
     return ['http' => ['method' => $request->getMethod(), 'header' => trim($headers), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => true, 'follow_location' => 0, 'content' => (string) $request->getBody()]];
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:8,代码来源:StreamAdapter.php

示例8: error

 /**
  * Handle an error. We handle errors by throwing an exception.
  *
  * @param string $error An error code representing the error
  *                      (use_underscore_separators).
  * @param string|null $message The error message.
  * @param \GuzzleHttp\Message\RequestInterface|null $request Optional. The
  *                                                  Guzzle request object.
  * @param \GuzzleHttp\Message\ResponseInterface|null $response Optional. The
  *                                                   Guzzle response object.
  *
  * @return void
  * @throws \Box\View\BoxViewException
  */
 protected static function error($error, $message = null, $request = null, $response = null)
 {
     if (!empty($request)) {
         $message .= "\n";
         $message .= 'Method: ' . $request->getMethod() . "\n";
         $message .= 'URL: ' . $request->getUrl() . "\n";
         $message .= 'Query: ' . json_encode($request->getQuery()->toArray()) . "\n";
         $message .= 'Headers: ' . json_encode($request->getHeaders()) . "\n";
         $message .= 'Request Body: ' . $request->getBody() . "\n";
     }
     if (!empty($response)) {
         $message .= "\n";
         $message .= 'Response Body: ' . $response->getBody() . "\n";
     }
     $exception = new BoxViewException($message);
     $exception->errorCode = $error;
     throw $exception;
 }
开发者ID:anx-hnezbeda,项目名称:php-box-view,代码行数:32,代码来源:Request.php

示例9: getZboziApiRequest

 /**
  * @param \GuzzleHttp\Message\RequestInterface $request
  * @return \SlevomatZboziApi\Request\ZboziApiRequest
  */
 private function getZboziApiRequest(\GuzzleHttp\Message\RequestInterface $request)
 {
     return new ZboziApiRequest($request->getMethod(), $request->getUrl(), $request->getHeaders(), $request->getBody() === null ? null : json_decode((string) $request->getBody()));
 }
开发者ID:pepakriz,项目名称:zbozi-api-php-library,代码行数:8,代码来源:RequestMaker.php

示例10: createCanonicalizedAmzHeaders

 private function createCanonicalizedAmzHeaders(RequestInterface $request)
 {
     $headers = [];
     foreach ($request->getHeaders() as $name => $header) {
         $name = strtolower($name);
         if (strpos($name, 'x-amz-') === 0) {
             $value = implode(',', $header);
             if (strlen($value) > 0) {
                 $headers[$name] = $name . ':' . $value;
             }
         }
     }
     if (!$headers) {
         return '';
     }
     ksort($headers);
     return implode("\n", $headers) . "\n";
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:18,代码来源:S3Signature.php

示例11: moveHeadersToQuery

 private function moveHeadersToQuery(RequestInterface $request)
 {
     $query = $request->getQuery();
     foreach ($request->getHeaders() as $name => $header) {
         $name = strtolower($name);
         if (substr($name, 0, 5) == 'x-amz') {
             $query[$name] = $header;
         }
         if ($name !== 'host') {
             $request->removeHeader($name);
         }
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:13,代码来源:SignatureV4.php

示例12: collectRequest

 /**
  * Collect & sanitize data about a Guzzle request.
  *
  * @param RequestInterface $request Guzzle request.
  * @return array
  */
 private function collectRequest(RequestInterface $request)
 {
     $query = $request->getQuery();
     return ['headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'path' => $request->getPath(), 'query' => (string) $query, 'queryParams' => $query->toArray(), 'body' => (string) $request->getBody()];
 }
开发者ID:campru,项目名称:guzzle-bundle,代码行数:11,代码来源:GuzzleDataCollector.php


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