Hi @yukulelix if you have access to the response object you may use as follow:
$response->headers->set('key','value');
I think using a Global Middleware you could specify that.
Hope it helps you.
Hi there, I am trying to create loading bars for my ajax powered website.
I would need Laravel to put a content-length header on my php pages. Any ideas on how to do that ?
Cheers !
Félix
//file: app/Http/Middleware/AddContentLength.php
<?php namespace App\Http\Middleware;
use Closure;
class AddContentLength {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->header('Content-Length',strlen($response->getOriginalContent()));
return $response;
}
}
Add the middleware inside app/Http/Kernel.php:
protected $middleware = [
'...............',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\AddContentLength'
];
Usman.
Please or to participate in this conversation.