A current issue in a setup that involved Drupal (Pressflow), Varnish and AuthCache, made me wonder about the correctness of the header "Content Length" in the following snippet (taken from authcache.helpers.inc):

  // Fast compression
  if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE && variable_get('page_compression', TRUE) && function_exists('gzencode') && zlib_get_coding_type() == FALSE) {
    $output = gzencode($output, 1, FORCE_GZIP);
    header('Content-Encoding: gzip');
  }
  …
  header("Content-Length: " . strlen($output));

Each page-request that reached this snippet resulted in a 503 error from Varnish. In the end, this was caused by having compression turned on in php.ini, rather than using the page compression of Drupal itself. As in this scenario strlen($output); sets the length of the uncompressed output, while Varnish still receives compressed content (due to the php.ini setting), but now with an incorrect Content-Length header. Requests that could take their content from the already filled AuthCache bin, did not throw 503's as they didn't reach this snippet.

The solution we choose was turning off the php.ini compression and relying on Drupal page compression instead, as it was preferred over commenting out the Content-Length header.

However, shouldn't the above structure be modified so that strlen($output) will only be set when zlib_get_coding_type returns FALSE, to avoid possible conflicts?

Comments

znerol’s picture

Status: Active » Closed (outdated)