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


PHP RequestInterface::getProtocolVersion方法代码示例

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


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

示例3: 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

示例4: addExpectHeader

 private function addExpectHeader(RequestInterface $request, StreamInterface $body)
 {
     // Determine if the Expect header should be used
     if ($request->hasHeader('Expect')) {
         return;
     }
     $expect = $request->getConfig()['expect'];
     // Return if disabled or if you're not using HTTP/1.1
     if ($expect === false || $request->getProtocolVersion() !== '1.1') {
         return;
     }
     // The expect header is unconditionally enabled
     if ($expect === true) {
         $request->setHeader('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
     $size = $body->getSize();
     if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
         $request->setHeader('Expect', '100-Continue');
     }
 }
开发者ID:ChenOhayon,项目名称:sitepoint_codes,代码行数:27,代码来源:Prepare.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: format

 /**
  * Returns a formatted message
  *
  * @param RequestInterface  $request    Request that was sent
  * @param ResponseInterface $response   Response that was received
  * @param \Exception        $error      Exception that was received
  * @param array             $customData Associative array of custom template data
  *
  * @return string
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = array())
 {
     $cache = $customData;
     $that = $this;
     return preg_replace_callback('/{\\s*([A-Za-z_\\-\\.0-9]+)\\s*}/', function (array $matches) use($request, $response, $error, &$cache, $that) {
         if (isset($cache[$matches[1]])) {
             return $cache[$matches[1]];
         }
         $result = '';
         switch ($matches[1]) {
             case 'request':
                 $result = $request;
                 break;
             case 'response':
                 $result = $response;
                 break;
             case 'req_headers':
                 $result = trim($request->getMethod() . ' ' . $request->getResource()) . ' HTTP/' . $request->getProtocolVersion() . "\r\n" . $that->headers($request);
                 break;
             case 'res_headers':
                 $result = $response ? sprintf('HTTP/%s %d %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()) . "\r\n" . $that->headers($response) : 'NULL';
                 break;
             case 'req_body':
                 $result = $request->getBody();
                 break;
             case 'res_body':
                 $result = $response ? $response->getBody() : 'NULL';
                 break;
             case 'ts':
                 $result = gmdate('c');
                 break;
             case 'method':
                 $result = $request->getMethod();
                 break;
             case 'url':
                 $result = $request->getUrl();
                 break;
             case 'resource':
                 $result = $request->getResource();
                 break;
             case 'req_version':
                 $result = $request->getProtocolVersion();
                 break;
             case 'res_version':
                 $result = $response ? $response->getProtocolVersion() : 'NULL';
                 break;
             case 'host':
                 $result = $request->getHost();
                 break;
             case 'hostname':
                 $result = gethostname();
                 break;
             case 'code':
                 $result = $response ? $response->getStatusCode() : 'NULL';
                 break;
             case 'phrase':
                 $result = $response ? $response->getReasonPhrase() : 'NULL';
                 break;
             case 'error':
                 $result = $error ? $error->getMessage() : 'NULL';
                 break;
             default:
                 // handle prefixed dynamic headers
                 if (strpos($matches[1], 'req_header_') === 0) {
                     $result = $request->getHeader(substr($matches[1], 11));
                 } elseif (strpos($matches[1], 'res_header_') === 0) {
                     $result = $response ? $response->getHeader(substr($matches[1], 11)) : 'NULL';
                 }
         }
         $cache[$matches[1]] = $result;
         return $result;
     }, $this->template);
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:83,代码来源:Formatter.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: getParameters

 /**
  * Get context fields to add to the time-line entry.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param Exception         $error
  *
  * @return array
  */
 protected function getParameters(RequestInterface $request, ResponseInterface $response = null, Exception $error = null)
 {
     $params = [];
     $keys = array_intersect($this->context, $this->availableParameters);
     foreach ($keys as $key) {
         switch ($key) {
             case 'request':
                 $result = $request;
                 break;
             case 'response':
                 $result = $response;
                 break;
             case 'method':
                 $result = $request->getMethod();
                 break;
             case 'url':
                 $result = $request->getUrl();
                 break;
             case 'resource':
                 $result = $request->getResource();
                 break;
             case 'request_version':
                 $result = $request->getProtocolVersion();
                 break;
             case 'response_version':
                 $result = $response ? $response->getProtocolVersion() : 'NULL';
                 break;
             case 'host':
                 $result = $request->getHost();
                 break;
             case 'hostname':
                 $result = gethostname();
                 break;
             case 'status_code':
                 $result = $response ? $response->getStatusCode() : 'NULL';
                 break;
             case 'phrase':
                 $result = $response ? $response->getReasonPhrase() : 'NULL';
                 break;
             case 'error':
                 $result = $error ? $error->getMessage() : 'NULL';
                 break;
         }
         $params[$key] = (string) $result ?: '';
     }
     return $params;
 }
开发者ID:jezzdk,项目名称:guzzle-debugbar,代码行数:56,代码来源:DebugbarSubscriber.php


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