csarrazi / CsaGuzzleBundle

A bundle integrating Guzzle >=4.0 in Symfony
250 stars 76 forks source link

X-Cache headers in list.html.twig #242

Open fnash opened 5 years ago

fnash commented 5 years ago

It would be interesting displaying Varnish headers (or custom headers) in the profiler with bootstrap badges. I make many GET requests in my app and it would be nice to easily know which requests made hit/miss from Varnish, with Age and Total-Hits.

Any guidelines to make a PR?

Make a new default middleware available

class VarnishCacheMiddleware extends CacheMiddleware
{
    const DEBUG_HEADER = 'X-Cache';
}

with

# GuzzleCollector

                if ($response->hasHeader('X-Cache') && 'HIT' === $response->getHeaderLine('X-Cache')) {
                    if ($response->hasHeader('Age')) {
                        $req['varnish']['age'] = $response->getHeaderLine('Age');
                    }

                    if ($response->hasHeader('X-Cache-Hits')) {
                        $req['varnish']['hits'] = $response->getHeaderLine('X-Cache-Hits');
                    }
                }
csarrazi commented 5 years ago

Hi @fnash. I guess the better approach might be to provide extension capabilities to the collector, in order to provide means to extend the current one. We could consider registering services associated to a tag, which would extract some additional information from the request, and let one extend the bundle that way.

What could be great would be to have the possibility to add new sections in the profiler page for each "extension".