Commit 1dd08a42 authored by Marc Egger's avatar Marc Egger

RestClient: enable default header setting in _script + small doku fix

parent b6c43d4a
Pipeline #3819 passed with stages
in 6 minutes and 26 seconds
......@@ -1411,7 +1411,7 @@ Run a php function defined in an external script.
* All column parameters are passed as an associative array to the function as the first argument.
* The second argument (here called $qfq) is an object which acts as an interface to QFQ functionality.
* The script has access to the following qfq functions using this interface:
* $qfq::apiCall($method, $url, $data = [], $header = [], $timeout = 5)
* $qfq::apiCall($method, $url, $data = '', $header = [], $timeout = 5)
* string $method can be PUT/POST/GET/DELETE
* string $url
* array $data a json string which will be added as GET parameters or as POST fields respectively.
......
......@@ -106,15 +106,6 @@ class RestClient {
$header = [];
}
if (strpos($param[TOKEN_L_HEADER], 'content-type:') === false) {
$mime = (($param[TOKEN_L_CONTENT][0] ?? '') == '{') ? 'application/json' : 'text/plain';
$header[] = 'content-type: ' . $mime . '; charset=utf-8';
}
if (strpos($param[TOKEN_L_HEADER], 'connection:') === false) {
$header[] = 'connection: close';
}
// If 'Host' is missing in header: define - useful for Firewall/ Proxy
// CR: if a header 'host' is given, REST calls fails always.
// if (strpos($param[TOKEN_L_HEADER], 'host:') === false) {
......@@ -128,6 +119,17 @@ class RestClient {
public static function callApiCurl(string $method, string $url, string $data = '', array $header = [], int $timeout = 5) {
// Header: Set content-type if not set
if (strpos(join('', $header), 'content-type:') === false) {
$mime = (($data[0] ?? '') == '{') ? 'application/json' : 'text/plain';
$header[] = 'content-type: ' . $mime . '; charset=utf-8';
}
// Header: Set connection if not set
if (strpos(join('', $header), 'connection:') === false) {
$header[] = 'connection: close';
}
$ch = curl_init();
$curlConfig = array(
CURLOPT_RETURNTRANSFER => true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment