本文整理汇总了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();
}
示例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;
}
示例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';
}
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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]);
}
示例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";
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}