added headers for module

This commit is contained in:
Devin Smith 2015-02-26 14:55:45 -08:00
parent c99432d717
commit b0cab299e2
2 changed files with 54 additions and 0 deletions

View File

@ -13,6 +13,8 @@ class Crunchbutton_App extends Cana_App {
private $_crypt;
public function init($params = null) {
set_exception_handler([$this, 'exception']);
Crunchbutton_Headers;
if (!$_SERVER['SERVER_NAME']) {
$cli = true;
// get the env send by parameter

View File

@ -0,0 +1,52 @@
<?php
// Drop-in replacement for apache_request_headers() when it's not available
class Crunchbutton_Headers{}
if(!function_exists('apache_request_headers')) {
function apache_request_headers() {
// Based on: http://www.iana.org/assignments/message-headers/message-headers.xml#perm-headers
$arrCasedHeaders = array(
// HTTP
'Dasl' => 'DASL',
'Dav' => 'DAV',
'Etag' => 'ETag',
'Mime-Version' => 'MIME-Version',
'Slug' => 'SLUG',
'Te' => 'TE',
'Www-Authenticate' => 'WWW-Authenticate',
// MIME
'Content-Md5' => 'Content-MD5',
'Content-Id' => 'Content-ID',
'Content-Features' => 'Content-features',
);
$arrHttpHeaders = array();
foreach($_SERVER as $strKey => $mixValue) {
if('HTTP_' !== substr($strKey, 0, 5)) {
continue;
}
$strHeaderKey = strtolower(substr($strKey, 5));
if(0 < substr_count($strHeaderKey, '_')) {
$arrHeaderKey = explode('_', $strHeaderKey);
$arrHeaderKey = array_map('ucfirst', $arrHeaderKey);
$strHeaderKey = implode('-', $arrHeaderKey);
}
else {
$strHeaderKey = ucfirst($strHeaderKey);
}
if(array_key_exists($strHeaderKey, $arrCasedHeaders)) {
$strHeaderKey = $arrCasedHeaders[$strHeaderKey];
}
$arrHttpHeaders[$strHeaderKey] = $mixValue;
}
return $arrHttpHeaders;
}
}