1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

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
This commit is contained in:
epriestley 2016-12-14 05:37:10 -08:00
parent 0c6e03d5af
commit 5215eb3067
2 changed files with 34 additions and 13 deletions

View file

@ -303,18 +303,7 @@ abstract class AphrontApplicationConfiguration extends Phobject {
phlog($unexpected_output); phlog($unexpected_output);
if ($response instanceof AphrontWebpageResponse) { if ($response instanceof AphrontWebpageResponse) {
echo phutil_tag( $response->setUnexpectedOutput($unexpected_output);
'div',
array(
'style' =>
'background: #eeddff;'.
'white-space: pre-wrap;'.
'z-index: 200000;'.
'position: relative;'.
'padding: 8px;'.
'font-family: monospace',
),
$unexpected_output);
} }
} }

View file

@ -3,14 +3,46 @@
final class AphrontWebpageResponse extends AphrontHTMLResponse { final class AphrontWebpageResponse extends AphrontHTMLResponse {
private $content; private $content;
private $unexpectedOutput;
public function setContent($content) { public function setContent($content) {
$this->content = $content; $this->content = $content;
return $this; return $this;
} }
public function setUnexpectedOutput($unexpected_output) {
$this->unexpectedOutput = $unexpected_output;
return $this;
}
public function getUnexpectedOutput() {
return $this->unexpectedOutput;
}
public function buildResponseString() { 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);
} }
} }