barryvdh / laravel-httpcache

Laravel HTTP Cache
480 stars 41 forks source link

ESI #37

Open patrikden opened 6 years ago

patrikden commented 6 years ago

Version 0.3.0 installed on laravel 5.4.

I try get ESI functionality. I have index page with included:

<esi:include src="{{ route('get-esi') }}"/>

And route to partial:

Route::get('/get-esi', ['as' => 'get-esi', 'uses' => 'IndexController@getesi']);

route('get-esi') conatain only

<h1>Hi! TEST</h1> 

and nothing else. When I'm open it in new window - thats work fine, only

Hi! TEST

on the page.

But when i Try include it like ESI I try get ESI functionality. I have index page with included:

<esi:include src="{{ route('get-esi') }}"/>

it load index page instead of route('get-esi').

What do I wrong? Please help

vadson777 commented 6 years ago

I have the same issue. When I include esi tag, middleware parses it, but the answer for esi is the index page. If index page has esi tag initially, than I get infinite loop of rendering the same page again and again. I tried to debug, and I found out that Symfony's HttpCache creates a subrequest with the right url (from esi tag), but the answer for this subrequest is index page. But if I try to open this esi-url in new tab I get the right answer.

dresb commented 6 years ago

I can confirm this issue. A simple test, like

Route::get('esi-get', function () {
    return 'esi content';  
});
Route::group(['middleware' => ['httpcache', 'ttl:300']], function () {  
    Route::get('esi-test', function () {
        return '<div><esi:include src="http://localhost.laravel/esi-get" /></div>';
    });
});

Generates a cached page in storage/httpcache:

<div><?php echo $this->surrogate->handle($this, 'http://localhost.laravel/esi-get', '', false) ?></div>

Which Outputs:

<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>...

In perpetuity until it runs out of memory when visited.

carlosvini commented 5 years ago

Same error here, the sub request is dispatched through the middlewares but the route remains the same of the main request.

josearagon commented 4 years ago

Hello @barryvdh,

I have same error. ESI include has been create an infinite loop that throw an allowed memory time error or max execution time exceeded.

Can you check it or help me please?

Thanks a lot!