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
Example #1
0
 /**
  * @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());
 }
Example #2
0
 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'));
 }
Example #3
0
 /**
  * @param Request $request
  *
  * @return Request
  */
 public function setupRequest(Request $request)
 {
     $request->defaultHeader('Authorization', sprintf('Bearer %s', $this->token));
     return $request;
 }