From 067b04aaf148cd57aff57ca2b52efcf95b4f70e7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 Apr 2020 12:12:37 -0700 Subject: [PATCH] If HTTP response headers are already sent, don't fiddle with "zlib.output_compression" Summary: We write some synthetic HTTP responses inside unit tests. Some responses have an indirect side effect of adjusting "zlib.output_compression", but this adjustment fails if headers have already been output. From a CLI context, headers appear to count as already-output after we write anything to stdout: ``` shouldCompressResponse()) { - // Enable automatic compression here. Webservers sometimes do this for - // us, but we now detect the absence of compression and warn users about - // it so try to cover our bases more thoroughly. - ini_set('zlib.output_compression', 1); - } else { - ini_set('zlib.output_compression', 0); + // If we've already sent headers, these "ini_set()" calls will warn that + // they have no effect. Today, this always happens because we're inside + // a unit test, so just skip adjusting the setting. + + if (!headers_sent()) { + if ($this->shouldCompressResponse()) { + // Enable automatic compression here. Webservers sometimes do this for + // us, but we now detect the absence of compression and warn users about + // it so try to cover our bases more thoroughly. + ini_set('zlib.output_compression', 1); + } else { + ini_set('zlib.output_compression', 0); + } } }