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