defaultHeaders() public static method

Set default headers to send on every request
public static defaultHeaders ( array $headers ) : array
$headers array headers array
return array
示例#1
0
 public function testDefaultHeaders()
 {
     $defaultHeaders = array('header1' => 'Hello', 'header2' => 'world');
     Request::defaultHeaders($defaultHeaders);
     $response = Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertObjectHasAttribute('header1', $response->body->headers);
     $this->assertEquals('Hello', $response->body->headers->header1);
     $this->assertObjectHasAttribute('header2', $response->body->headers);
     $this->assertEquals('world', $response->body->headers->header2);
     $response = Request::get('http://mockbin.com/request', ['header1' => 'Custom value']);
     $this->assertEquals(200, $response->code);
     $this->assertObjectHasAttribute('header1', $response->body->headers);
     $this->assertEquals('Custom value', $response->body->headers->header1);
     Request::clearDefaultHeaders();
     $response = Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertObjectNotHasAttribute('header1', $response->body->headers);
     $this->assertObjectNotHasAttribute('header2', $response->body->headers);
 }