Skip to content

Commit

Permalink
Fixed CONTENT_TYPE issue to support both Apache and Nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoyi Cao committed Jan 31, 2019
1 parent 6fd0c71 commit 546c8f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion html/components/basic-func/external-libs.html
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
<script src="../../bower_components/pako/dist/pako.js"></script>
11 changes: 8 additions & 3 deletions includes/common_func.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,20 @@ function getRequest() {
// This function also needs to handle preflight for CORS
if ($_SERVER['REQUEST_METHOD'] !== 'OPTIONS') {
// This is not a CORS preflight request
if(isset($_SERVER['HTTP_CONTENT_TYPE'])) {
switch(explode('; ', strtolower($_SERVER['HTTP_CONTENT_TYPE']), 2)[0]) {
$contentType = isset($_SERVER['HTTP_CONTENT_TYPE'])
? $_SERVER['HTTP_CONTENT_TYPE']
: isset($_SERVER['CONTENT_TYPE'])
? $_SERVER['CONTENT_TYPE']
: '';
if($contentType) {
switch(explode('; ', strtolower($contentType), 2)[0]) {
case 'application/json':
return json_decode(file_get_contents('php://input'), true);
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
return $_REQUEST;
default:
error_log('Content-type not recognized: get \'' . $_SERVER['HTTP_CONTENT_TYPE'] . '\'');
error_log('Content-type not recognized: get \'' . $contentType . '\'');
return file_get_contents('php://input');
}
} else {
Expand Down

0 comments on commit 546c8f4

Please sign in to comment.