From 76884adefab530ea3ac5cdec81a27104f36a5ce0 Mon Sep 17 00:00:00 2001 From: Lieven Janssen Date: Thu, 8 May 2014 15:01:52 +0200 Subject: [PATCH 1/2] content-type header can contain encoding, e.g. application/x-www-form-urlencoded; charset=utf-8 Did a string comparison on the string before the first ;. --- index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index ed31d942..34389703 100644 --- a/index.php +++ b/index.php @@ -242,12 +242,13 @@ if ((array_key_exists('CONTENT_TYPE', $_SERVER) === true) && (empty($data) !== true)) { - if (strcasecmp($_SERVER['CONTENT_TYPE'], 'application/json') === 0) + $contenttype = explode(";",$_SERVER['CONTENT_TYPE'])[0]; + if (strcasecmp($contenttype, 'application/json') === 0) { $GLOBALS['_' . $http] = json_decode($data, true); } - else if ((strcasecmp($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') === 0) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'PUT') === 0)) + else if ((strcasecmp($contenttype, 'application/x-www-form-urlencoded') === 0) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'PUT') === 0)) { parse_str($data, $GLOBALS['_' . $http]); } From af308ee23ac0dfc32ac8855151bf870051433d43 Mon Sep 17 00:00:00 2001 From: Lieven Janssen Date: Fri, 9 May 2014 17:13:36 +0200 Subject: [PATCH 2/2] content-type fix with strncasecmp --- index.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 34389703..8c8df4e4 100644 --- a/index.php +++ b/index.php @@ -242,13 +242,12 @@ if ((array_key_exists('CONTENT_TYPE', $_SERVER) === true) && (empty($data) !== true)) { - $contenttype = explode(";",$_SERVER['CONTENT_TYPE'])[0]; - if (strcasecmp($contenttype, 'application/json') === 0) + if (strncasecmp($_SERVER['CONTENT_TYPE'], 'application/json', 16) === 0) { $GLOBALS['_' . $http] = json_decode($data, true); } - else if ((strcasecmp($contenttype, 'application/x-www-form-urlencoded') === 0) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'PUT') === 0)) + else if ((strncasecmp($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded', 33) === 0) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'PUT') === 0)) { parse_str($data, $GLOBALS['_' . $http]); }