Skip to content

Commit d9a6824

Browse files
Added support for static content types
1 parent 86a3074 commit d9a6824

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

pfSense-pkg-API/files/etc/inc/api/framework/APITools.inc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@ require_once("auth.inc");
3030
require_once("functions.inc");
3131
use Firebase\JWT\JWT;
3232

33-
# Gathers our URL form encoded data or JSON body data from our request and places them in a single array
33+
# Checks our content type header and parses the content accordingly
3434
function get_request_data() {
35-
$data = $_GET; // Accept HTTP requests in URL encoded format
36-
// Check if our URL encoded parameters are empty, if so try JSON encoded parameters
37-
if (empty($data)) {
38-
$data = json_decode(file_get_contents('php://input'), true);
35+
# Support application/x-www-form-urlencoded content type
36+
if (strtolower($_SERVER["HTTP_CONTENT_TYPE"] === "application/x-www-form-urlencoded")) {
37+
return $_GET;
38+
}
39+
# Support application/json content type
40+
elseif (strtolower($_SERVER["HTTP_CONTENT_TYPE"] === "application/json")) {
41+
return json_decode(file_get_contents('php://input'), true);
42+
}
43+
# If a static content type was not provided, attempt to determine the content type
44+
else {
45+
if (!empty($_GET)) {
46+
return $_GET;
47+
} else {
48+
return json_decode(file_get_contents('php://input'), true);
49+
}
3950
}
40-
return $data;
4151
}
4252

4353
# Check our local pfSense version

0 commit comments

Comments
 (0)