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


PHP Request::setScheme方法代码示例

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


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

示例1: testCatchesAllHostHeaderChanges

 /**
  * @covers Guzzle\Http\Message\Request::changedHeader
  * @covers Guzzle\Http\Message\Request::setHeader
  */
 public function testCatchesAllHostHeaderChanges()
 {
     // Tests setting using headers
     $this->request->setHeader('Host', 'www.abc.com');
     $this->assertEquals('www.abc.com', $this->request->getHost());
     $this->assertEquals('www.abc.com:8124', $this->request->getHeader('Host'));
     $this->assertEquals(8124, $this->request->getPort());
     // Tests setting using setHost()
     $this->request->setHost('abc.com');
     $this->assertEquals('abc.com', $this->request->getHost());
     $this->assertEquals('abc.com:8124', $this->request->getHeader('Host'));
     $this->assertEquals(8124, $this->request->getPort());
     // Tests setting with a port
     $this->request->setHost('abc.com:8081');
     $this->assertEquals('abc.com', $this->request->getHost());
     $this->assertEquals('abc.com:8081', $this->request->getHeader('Host'));
     $this->assertEquals(8081, $this->request->getPort());
     // Tests setting with a port using the Host header
     $this->request->setHeader('Host', 'solr.com:8983');
     $this->assertEquals('solr.com', $this->request->getHost());
     $this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
     $this->assertEquals(8983, $this->request->getPort());
     // Tests setting with an inferred 443 port using the Host header
     $this->request->setScheme('https');
     $this->request->setHeader('Host', 'solr.com');
     $this->assertEquals('solr.com', $this->request->getHost());
     $this->assertEquals('solr.com:8983', (string) $this->request->getHeader('Host'));
     $this->assertEquals(8983, $this->request->getPort());
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:33,代码来源:RequestTest.php

示例2: generateRequest

 protected function generateRequest($url, array $subProtocols, array $headers)
 {
     $headers = array_merge($this->defaultHeaders, $headers);
     $headers['Sec-WebSocket-Key'] = $this->generateKey();
     $request = new Request('GET', $url, $headers);
     $scheme = strtolower($request->getScheme());
     if (!in_array($scheme, ['ws', 'wss'])) {
         throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
     }
     $request->setScheme('HTTP');
     if (!$request->getPort()) {
         $request->setPort('wss' === $scheme ? 443 : 80);
     } else {
         $request->setHeader('Host', $request->getHeader('Host') . ":{$request->getPort()}");
     }
     if (!$request->getHeader('Origin')) {
         $request->setHeader('Origin', str_replace('ws', 'http', $scheme) . '://' . $request->getHost());
     }
     // do protocol headers
     if (count($subProtocols) > 0) {
         $protocols = implode(',', $subProtocols);
         if ($protocols != "") {
             $request->setHeader('Sec-WebSocket-Protocol', $protocols);
         }
     }
     return $request;
 }
开发者ID:brainverb,项目名称:Pawl,代码行数:27,代码来源:Factory.php

示例3: testCanChangePortThroughScheme

 public function testCanChangePortThroughScheme()
 {
     $request = new Request('GET', 'http://foo.com');
     $request->setScheme('https');
     $this->assertEquals('https://foo.com', (string) $request->getUrl());
     $this->assertEquals('foo.com', $request->getHost());
     $request->setScheme('http');
     $this->assertEquals('http://foo.com', (string) $request->getUrl());
     $this->assertEquals('foo.com', $request->getHost());
     $request->setPort(null);
     $this->assertEquals('http://foo.com', (string) $request->getUrl());
     $this->assertEquals('foo.com', $request->getHost());
 }
开发者ID:jorjoh,项目名称:Varden,代码行数:13,代码来源:RequestTest.php

示例4: testRequestHasScheme

 public function testRequestHasScheme()
 {
     $this->assertEquals('http', $this->request->getScheme());
     $this->assertEquals($this->request, $this->request->setScheme('https'));
     $this->assertEquals('https', $this->request->getScheme());
 }
开发者ID:mickdane,项目名称:zidisha,代码行数:6,代码来源:RequestTest.php


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