defaultHeader() public static method

Set a new default header to send on every request
public static defaultHeader ( string $name, string $value ) : string
$name string header name
$value string header value
return string
コード例 #1
0
ファイル: Request.php プロジェクト: codecasts/restinga
 /**
  * @param \Codecasts\Restinga\Contracts\Data\Resource $resource
  * @param bool                                        $identified
  */
 public function __construct(Resource $resource, $identified = false)
 {
     $this->resource = $resource;
     $this->identified = $identified;
     $this->descriptor = $this->resource->getDescriptor();
     $this->request = new Unirest\Request();
     $this->request = $this->descriptor->authorization()->setupRequest($this->request);
     $this->request->defaultHeader('Content-Type', $this->resource->getContentTypeHeader());
     $this->request->defaultHeader('Accept', $this->resource->getAcceptHeader());
 }
コード例 #2
0
ファイル: RequestTest.php プロジェクト: RusinovIG/unirest-php
 public function testDefaultHeader()
 {
     Request::defaultHeader('Hello', 'custom');
     $response = Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertTrue(property_exists($response->body->headers, 'hello'));
     $this->assertEquals('custom', $response->body->headers->hello);
     Request::clearDefaultHeaders();
     $response = Request::get('http://mockbin.com/request');
     $this->assertEquals(200, $response->code);
     $this->assertFalse(property_exists($response->body->headers, 'hello'));
 }
コード例 #3
0
ファイル: Bearer.php プロジェクト: codecasts/restinga
 /**
  * @param Request $request
  *
  * @return Request
  */
 public function setupRequest(Request $request)
 {
     $request->defaultHeader('Authorization', sprintf('Bearer %s', $this->token));
     return $request;
 }