tracy icon indicating copy to clipboard operation
tracy copied to clipboard

Setting content-length header strips debugger output

Open urugator opened this issue 5 years ago • 0 comments

While it makes sense, it's not immediately obvious why the tracy bar isn't showing up. I think it would be beneficial to mention this in docs.

What are the possible solutions? Currently I simply ignore the content-length header when debugger is enabled:

private function emitHeaders(ResponseInterface $response) : void {
    $statusCode = $response->getStatusCode();
    foreach ($response->getHeaders() as $name => $value) {
      $normalizedName = self::normalizeHeaderName($name);
      // The additional output generated by debugger is stripped by client/server when content-length is set
      if (Debugger::isEnabled() && $name === 'content-length') {
        continue;
      }
      header("$normalizedName: $value", true, $statusCode);
    }
    foreach ($response->getCookies() as $cookie) {
      header($cookie->toHeader(), false, $statusCode);
    }
}

But clearly it's not ideal and possibly problematic when using a 3rd party lib/framework. Can omitted content-length header cause any trouble (considering usual http clients)?

Is it perhaps possible to intercept/capture the debugger's output, so it can be added to response manually? However that would limit the "scope" of what the Debugger is able to capture, so probably not the best idea either...?

Related #255

urugator avatar Sep 20 '20 22:09 urugator