public function test_extract_auth_headers() { $parser = new ReceivedHeadersParser(); $headers = new HttpHeaders(); $this->assertFalse($headers->has('authorization')); $parser->extractAuthHeaders($headers, ['HTTP_AUTHORIZATION' => 'Bearer foo']); $this->assertEquals('Bearer foo', $headers->find('authorization')); $parser->extractAuthHeaders($headers, ['HTTP_AUTHORIZATION' => 'Bearer bar']); $this->assertEquals('Bearer foo', $headers->find('authorization')); }
public function test_add() { $headers = new HttpHeaders(['cookie' => 'foo=bar;yolo=swag; bar=foo;']); $request = new HttpRequest(null, null, $headers); $jar = new CookieJar($request); $jar->set('xx', 'yy'); $this->assertEquals(1, count($headers->get('cookie'))); $this->assertEquals('yy', $jar->get('xx')); $this->assertEquals(1, count($headers->get('cookie'))); }
public function test_get_and_set_headers() { $response = new HttpResponse(); $this->assertTrue($response->getHeaders() instanceof IHttpHeaders); $headers = new HttpHeaders(); $headers->set('foo', 'bar'); $response->setHeaders($headers); $this->assertTrue($response->getHeaders() instanceof IHttpHeaders); $this->assertEquals($headers->find('foo'), $response->getHeaders()->find('foo')); $this->assertEquals($headers->find('foo'), $response->getHeaders()->find('foo')); $this->assertEquals('yolo', $response->getHeaders()->find('swag', 'yolo')); $response->getHeaders()->set('swag', 'yolo'); $this->assertEquals('yolo', $response->getHeaders()->find('swag')); }
public function test_construct() { $headers = new HttpHeaders(['foo' => 'bar', 'bar' => ['foo', 'baz']]); $this->assertEquals(['foo' => ['bar'], 'bar' => ['foo', 'baz']], $headers->toArray()); }