public function testResponseCanBeWrittenAndReadFromStorage() { $request = \PHPExtra\Proxy\Http\Request::create('test.html'); $response = new \PHPExtra\Proxy\Http\Response('Works'); $storage = new \PHPExtra\Proxy\Storage\InMemoryStorage(); $storage->save($request, $response); $response = $storage->fetch($request); $this->assertEquals('Works', $response->getBody()); }
public function testResponseDateIsNotModifiedByCacheListener() { $now = \DateTime::createFromFormat('D, d M Y H:i:s T', 'Fri, 12 Dec 2014 12:46:14 GMT'); $this->cacheStrategy->setCanUseResponseFromCache(true); $request = Request::create('/'); $response = new Response('"ok"'); $response->setDate($now); $this->storage->save($request, $response); $event = new ProxyRequestEvent($request, null, $this->proxy); $event->setLogger(new LoggerProxy()); $this->proxyCacheListener->onProxyRequest($event); $this->assertEquals('Fri, 12 Dec 2014 12:46:14 GMT', $response->getHeader('date')[0]); $this->assertEquals('HIT', $response->getHeader('X-Cache')[0]); }
public function testProxyAppendsViaHeaderToResponseWithoutViaHeader() { $request = \PHPExtra\Proxy\Http\Request::create('http://example.com/'); $this->adapter->setHandler(function (RequestInterface $request) { return new \PHPExtra\Proxy\Http\Response('OK', 200); }); $response = $this->proxy->handle($request); $viaHeaders = $response->getHeader('Via'); $this->assertEquals(1, count($viaHeaders)); $this->assertEquals('PHPExtraProxyServer', $viaHeaders[0]); }