當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。