From 5215eb3067912cfc3eaa83e7f094755a3dec6bde Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 14 Dec 2016 05:37:10 -0800 Subject: [PATCH] Fix an issue where unexpected debugging output would run afoul of automatic compression Summary: If you put "echo" or "print" statements into the code at random places (as I frequently do during development), they would emit before we enabled compression. This would confuse the compression mechanism and browser. I tried using `headers_sent()` to selectively disable compression but that didn't appear to fix this interaction (I think emitting this text does not cause headers to send, but does let contet escape into some buffer which the compressor can not access). Instead, push the header down a little bit so it renders after we activate compression. Also make it slightly fancier / more hideous. WOW. Test Plan: {F2122927} Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D17052 --- .../AphrontApplicationConfiguration.php | 13 +------ .../response/AphrontWebpageResponse.php | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/aphront/configuration/AphrontApplicationConfiguration.php b/src/aphront/configuration/AphrontApplicationConfiguration.php index aee2c63032..e7b3b85c63 100644 --- a/src/aphront/configuration/AphrontApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontApplicationConfiguration.php @@ -303,18 +303,7 @@ abstract class AphrontApplicationConfiguration extends Phobject { phlog($unexpected_output); if ($response instanceof AphrontWebpageResponse) { - echo phutil_tag( - 'div', - array( - 'style' => - 'background: #eeddff;'. - 'white-space: pre-wrap;'. - 'z-index: 200000;'. - 'position: relative;'. - 'padding: 8px;'. - 'font-family: monospace', - ), - $unexpected_output); + $response->setUnexpectedOutput($unexpected_output); } } diff --git a/src/aphront/response/AphrontWebpageResponse.php b/src/aphront/response/AphrontWebpageResponse.php index bda0d94244..de642f9b19 100644 --- a/src/aphront/response/AphrontWebpageResponse.php +++ b/src/aphront/response/AphrontWebpageResponse.php @@ -3,14 +3,46 @@ final class AphrontWebpageResponse extends AphrontHTMLResponse { private $content; + private $unexpectedOutput; public function setContent($content) { $this->content = $content; return $this; } + public function setUnexpectedOutput($unexpected_output) { + $this->unexpectedOutput = $unexpected_output; + return $this; + } + + public function getUnexpectedOutput() { + return $this->unexpectedOutput; + } + public function buildResponseString() { - return hsprintf('%s', $this->content); + $unexpected_output = $this->getUnexpectedOutput(); + if (strlen($unexpected_output)) { + $style = array( + 'background: linear-gradient(180deg, #eeddff, #ddbbff);', + 'white-space: pre-wrap;', + 'z-index: 200000;', + 'position: relative;', + 'padding: 16px;', + 'font-family: monospace;', + 'text-shadow: 1px 1px 1px white;', + ); + + $unexpected_header = phutil_tag( + 'div', + array( + 'style' => implode(' ', $style), + ), + $unexpected_output); + } else { + $unexpected_header = ''; + } + + return hsprintf('%s%s', $unexpected_header, $this->content); } }