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


PHP RequestInterface::getProtocolVersion方法代码示例

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


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

示例1: getProtocolVersion

 /**
  * Retrieves the HTTP protocol version as a string.
  *
  * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
  *
  * @return string HTTP protocol version.
  */
 public function getProtocolVersion()
 {
     if ($this->overRidingProtocol !== null) {
         return $this->overRidingProtocol;
     }
     return $this->request->getProtocolVersion();
 }
开发者ID:danack,项目名称:tier,代码行数:14,代码来源:TierResponse.php

示例2: formatRequest

 /**
  * {@inheritdoc}
  */
 public function formatRequest(RequestInterface $request)
 {
     $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment('')));
     if ($request->getProtocolVersion() === '1.0') {
         $command .= ' --http1.0';
     } elseif ($request->getProtocolVersion() === '2.0') {
         $command .= ' --http2';
     }
     $method = strtoupper($request->getMethod());
     if ('HEAD' === $method) {
         $command .= ' --head';
     } elseif ('GET' !== $method) {
         $command .= ' --request ' . $method;
     }
     $command .= $this->getHeadersAsCommandOptions($request);
     $body = $request->getBody();
     if ($body->getSize() > 0) {
         if (!$body->isSeekable()) {
             return 'Cant format Request as cUrl command if body stream is not seekable.';
         }
         $command .= sprintf(' --data %s', escapeshellarg($body->__toString()));
         $body->rewind();
     }
     return $command;
 }
开发者ID:php-http,项目名称:message,代码行数:28,代码来源:CurlCommandFormatter.php

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

示例4: formatRequest

 /**
  * {@inheritdoc}
  */
 public function formatRequest(RequestInterface $request)
 {
     $message = sprintf("%s %s HTTP/%s\n", $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion());
     foreach ($request->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\n";
     }
     return $this->addBody($request, $message);
 }
开发者ID:php-http,项目名称:message,代码行数:11,代码来源:FullHttpMessageFormatter.php

示例5: createRequest

 /**
  * Converts a PSR request into a Guzzle request.
  *
  * @param RequestInterface $request
  *
  * @return GuzzleRequest
  */
 private function createRequest(RequestInterface $request)
 {
     $options = ['exceptions' => false, 'allow_redirects' => false];
     $options['version'] = $request->getProtocolVersion();
     $options['headers'] = $request->getHeaders();
     $options['body'] = (string) $request->getBody();
     return $this->client->createRequest($request->getMethod(), (string) $request->getUri(), $options);
 }
开发者ID:parsingeye,项目名称:guzzle5-adapter,代码行数:15,代码来源:Guzzle5HttpAdapter.php

示例6: setupRequest

 /**
  * @return HttpRequest mixed
  */
 protected function setupRequest()
 {
     $headers = [];
     foreach ($this->request->getHeaders() as $key => $values) {
         $headers[$key] = implode(';', $values);
     }
     return $this->httpClient->request($this->request->getMethod(), (string) $this->request->getUri(), $headers, $this->request->getProtocolVersion());
 }
开发者ID:wyrihaximus,项目名称:react-guzzle-http-client,代码行数:11,代码来源:Request.php

示例7: transformRequestHeadersToString

 /**
  * Produce the header of request as a string based on a PSR Request
  *
  * @param RequestInterface $request
  *
  * @return string
  */
 protected function transformRequestHeadersToString(RequestInterface $request)
 {
     $message = vsprintf('%s %s HTTP/%s', [strtoupper($request->getMethod()), $request->getRequestTarget(), $request->getProtocolVersion()]) . "\r\n";
     foreach ($request->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\r\n";
     }
     $message .= "\r\n";
     return $message;
 }
开发者ID:printu,项目名称:socket-client,代码行数:16,代码来源:RequestWriter.php

示例8: request

 public static function request(RequestInterface $request)
 {
     $method = $request->getMethod();
     $url = $request->getUri();
     $body = $request->getBody()->getContents();
     $headers = $request->getHeaders();
     $protocolVersion = $request->getProtocolVersion();
     return new HttpObservable($method, $url, $body, $headers, $protocolVersion);
 }
开发者ID:RxPHP,项目名称:RxHttp,代码行数:9,代码来源:Http.php

示例9: createRequest

 /**
  * Converts a PSR request into a BuzzRequest request.
  *
  * @param RequestInterface $request
  *
  * @return BuzzRequest
  */
 private function createRequest(RequestInterface $request)
 {
     $buzzRequest = new BuzzRequest();
     $buzzRequest->setMethod($request->getMethod());
     $buzzRequest->fromUrl($request->getUri()->__toString());
     $buzzRequest->setProtocolVersion($request->getProtocolVersion());
     $buzzRequest->setContent((string) $request->getBody());
     $this->addPsrHeadersToBuzzRequest($request, $buzzRequest);
     return $buzzRequest;
 }
开发者ID:php-http,项目名称:buzz-adapter,代码行数:17,代码来源:Client.php

示例10: prepareHttpCUrl

 /**
  * Assigns options specific to handling HTTP requests.
  * NOTE: THIS METHOD SHOULD BE CALLED ONLY FROM prepareCUrl()!
  *
  * @throws UnsupportedFeatureException Thrown if POST method was requested.
  */
 private function prepareHttpCUrl()
 {
     if ($this->fetchRequest->getMethod() !== 'GET') {
         throw new UnsupportedFeatureException('Request other than GET are not supported');
     }
     $headers = [];
     foreach ($this->fetchRequest->getHeaders() as $name => $values) {
         $headers[] = $name . ": " . implode(", ", $values);
     }
     curl_setopt_array($this->cUrl, [CURLOPT_AUTOREFERER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_FAILONERROR => 1, CURLOPT_HTTP_VERSION => $this->fetchRequest->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_USERAGENT => $this->fetchRequest->getHeader('User-Agent') ?: $this->getDefaultUserAgent(), CURLOPT_HTTPHEADER => $headers]);
 }
开发者ID:kiler129,项目名称:TorrentGhost,代码行数:17,代码来源:FetchJob.php

示例11: getFileName

 protected function getFileName(RequestInterface $request)
 {
     $result = trim($request->getMethod() . ' ' . $request->getRequestTarget()) . ' HTTP/' . $request->getProtocolVersion();
     foreach ($request->getHeaders() as $name => $values) {
         if (array_key_exists(strtoupper($name), $this->ignored_headers)) {
             continue;
         }
         $result .= "\r\n{$name}: " . implode(', ', $values);
     }
     $request = $result . "\r\n\r\n" . $request->getBody();
     return md5((string) $request) . ".txt";
 }
开发者ID:Lidbetter,项目名称:GuzzleRecorder,代码行数:12,代码来源:GuzzleRecorder.php

示例12: toString

 /**
  * Serialize a request message to a string.
  *
  * @param RequestInterface $request
  * @return string
  */
 public static function toString(RequestInterface $request)
 {
     $headers = self::serializeHeaders($request->getHeaders());
     $body = (string) $request->getBody();
     $format = '%s %s HTTP/%s%s%s';
     if (!empty($headers)) {
         $headers = "\r\n" . $headers;
     }
     if (!empty($body)) {
         $headers .= "\r\n\r\n";
     }
     return sprintf($format, $request->getMethod(), $request->getRequestTarget(), $request->getProtocolVersion(), $headers, $body);
 }
开发者ID:deepfreeze,项目名称:zend-diactoros,代码行数:19,代码来源:Serializer.php

示例13: verifyAll

 /**
  * Given an array of the headers this method will run through all verification methods
  * @param 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->getUri()->getPath());
     $passes += (int) $this->verifyHost($request->getHeader('Host'));
     $passes += (int) $this->verifyUpgradeRequest($request->getHeader('Upgrade'));
     $passes += (int) $this->verifyConnection($request->getHeader('Connection'));
     $passes += (int) $this->verifyKey($request->getHeader('Sec-WebSocket-Key'));
     $passes += (int) $this->verifyVersion($request->getHeader('Sec-WebSocket-Version'));
     return 8 === $passes;
 }
开发者ID:RxPHP,项目名称:RxWebsocket,代码行数:18,代码来源:RequestVerifier.php

示例14: convertRequest

 /**
  * @return Request
  */
 protected function convertRequest(RequestInterface $request, array $options)
 {
     $artaxRequest = new Request();
     $artaxRequest->setProtocol($request->getProtocolVersion());
     $artaxRequest->setMethod($request->getMethod());
     $artaxRequest->setUri((string) $request->getUri());
     $artaxRequest->setAllHeaders($request->getHeaders());
     $body = $request->getBody();
     if ($body->getSize() === null || $body->getSize() > 0) {
         $body->rewind();
         $artaxRequest->setBody(new PsrStreamIterator($body));
     }
     return $artaxRequest;
 }
开发者ID:joshdifabio,项目名称:artax-guzzle-handler,代码行数:17,代码来源:ArtaxHandler.php

示例15: toString

 /**
  * Serialize a request message to a string.
  *
  * @param RequestInterface $request
  * @return string
  */
 public static function toString(RequestInterface $request)
 {
     $httpMethod = $request->getMethod();
     if (empty($httpMethod)) {
         throw new UnexpectedValueException('Object can not be serialized because HTTP method is empty');
     }
     $headers = self::serializeHeaders($request->getHeaders());
     $body = (string) $request->getBody();
     $format = '%s %s HTTP/%s%s%s';
     if (!empty($headers)) {
         $headers = "\r\n" . $headers;
     }
     if (!empty($body)) {
         $headers .= "\r\n\r\n";
     }
     return sprintf($format, $httpMethod, $request->getRequestTarget(), $request->getProtocolVersion(), $headers, $body);
 }
开发者ID:zendframework,项目名称:zend-diactoros,代码行数:23,代码来源:Serializer.php


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