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


PHP Response::hasHeader方法代码示例

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


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

示例1: testDoesTheSameAsResponseWhenDereferenced

 public function testDoesTheSameAsResponseWhenDereferenced()
 {
     $str = Stream::factory('foo');
     $response = new Response(200, ['Foo' => 'bar'], $str);
     $future = MockTest::createFuture(function () use($response) {
         return $response;
     });
     $this->assertFalse($this->readAttribute($future, 'isRealized'));
     $this->assertEquals(200, $future->getStatusCode());
     $this->assertTrue($this->readAttribute($future, 'isRealized'));
     // Deref again does nothing.
     $future->wait();
     $this->assertTrue($this->readAttribute($future, 'isRealized'));
     $this->assertEquals('bar', $future->getHeader('Foo'));
     $this->assertEquals(['bar'], $future->getHeaderAsarray('Foo'));
     $this->assertSame($response->getHeaders(), $future->getHeaders());
     $this->assertSame($response->getBody(), $future->getBody());
     $this->assertSame($response->getProtocolVersion(), $future->getProtocolVersion());
     $this->assertSame($response->getEffectiveUrl(), $future->getEffectiveUrl());
     $future->setEffectiveUrl('foo');
     $this->assertEquals('foo', $response->getEffectiveUrl());
     $this->assertSame($response->getReasonPhrase(), $future->getReasonPhrase());
     $this->assertTrue($future->hasHeader('foo'));
     $future->removeHeader('Foo');
     $this->assertFalse($future->hasHeader('foo'));
     $this->assertFalse($response->hasHeader('foo'));
     $future->setBody(Stream::factory('true'));
     $this->assertEquals('true', (string) $response->getBody());
     $this->assertTrue($future->json());
     $this->assertSame((string) $response, (string) $future);
     $future->setBody(Stream::factory('<a><b>c</b></a>'));
     $this->assertEquals('c', (string) $future->xml()->b);
     $future->addHeader('a', 'b');
     $this->assertEquals('b', $future->getHeader('a'));
     $future->addHeaders(['a' => '2']);
     $this->assertEquals('b, 2', $future->getHeader('a'));
     $future->setHeader('a', '2');
     $this->assertEquals('2', $future->getHeader('a'));
     $future->setHeaders(['a' => '3']);
     $this->assertEquals(['a' => ['3']], $future->getHeaders());
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:41,代码来源:FutureResponseTest.php


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