@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix an issue where PHP puts the content type in CONTENT_TYPE instead of HTTP_CONTENT_TYPE

Summary: Fixes T4084. See that task for discussion.

Test Plan: Did `git clone`. My setup doesn't precisely reproduce the original issue, but hopefully @enko can confirm this is a fix.

Reviewers: btrahan, enko

Reviewed By: enko

CC: enko, aran

Maniphest Tasks: T4084

Differential Revision: https://secure.phabricator.com/D7561

+50 -3
+33 -3
src/aphront/AphrontRequest.php
··· 466 466 } 467 467 468 468 469 - public static function getHTTPHeader($name, $default = null) { 469 + /** 470 + * Read the value of an HTTP header from `$_SERVER`, or a similar datasource. 471 + * 472 + * This function accepts a canonical header name, like `"Accept-Encoding"`, 473 + * and looks up the appropriate value in `$_SERVER` (in this case, 474 + * `"HTTP_ACCEPT_ENCODING"`). 475 + * 476 + * @param string Canonical header name, like `"Accept-Encoding"`. 477 + * @param wild Default value to return if header is not present. 478 + * @param array? Read this instead of `$_SERVER`. 479 + * @return string|wild Header value if present, or `$default` if not. 480 + */ 481 + public static function getHTTPHeader($name, $default = null, $data = null) { 470 482 // PHP mangles HTTP headers by uppercasing them and replacing hyphens with 471 483 // underscores, then prepending 'HTTP_'. 472 484 $php_index = strtoupper($name); 473 485 $php_index = str_replace('-', '_', $php_index); 474 - $php_index = 'HTTP_'.$php_index; 475 486 476 - return idx($_SERVER, $php_index, $default); 487 + $try_names = array(); 488 + 489 + $try_names[] = 'HTTP_'.$php_index; 490 + if ($php_index == 'CONTENT_TYPE' || $php_index == 'CONTENT_LENGTH') { 491 + // These headers may be available under alternate names. See 492 + // http://www.php.net/manual/en/reserved.variables.server.php#110763 493 + $try_names[] = $php_index; 494 + } 495 + 496 + if ($data === null) { 497 + $data = $_SERVER; 498 + } 499 + 500 + foreach ($try_names as $try_name) { 501 + if (array_key_exists($try_name, $data)) { 502 + return $data[$try_name]; 503 + } 504 + } 505 + 506 + return $default; 477 507 } 478 508 479 509 }
+17
src/aphront/__tests__/AphrontRequestTestCase.php
··· 131 131 } 132 132 } 133 133 134 + public function testGetHTTPHeader() { 135 + $server_data = array( 136 + 'HTTP_ACCEPT_ENCODING' => 'duck/quack', 137 + 'CONTENT_TYPE' => 'cow/moo', 138 + ); 139 + 140 + $this->assertEqual( 141 + 'duck/quack', 142 + AphrontRequest::getHTTPHeader('AcCePt-EncOdING', null, $server_data)); 143 + $this->assertEqual( 144 + 'cow/moo', 145 + AphrontRequest::getHTTPHeader('cONTent-TyPE', null, $server_data)); 146 + $this->assertEqual( 147 + null, 148 + AphrontRequest::getHTTPHeader('Pie-Flavor', null, $server_data)); 149 + } 150 + 134 151 }