public static function Nodejs::httpRequest in Node.js integration 7
13 calls to Nodejs::httpRequest()
File
- ./
nodejs.module, line 966
Class
Code
public static function httpRequest($url, $options = array(), $ignore_version = FALSE) {
self::initConfig();
if (!$ignore_version && !self::checkServerVersion()) {
return FALSE;
}
$options += array(
'method' => 'GET',
'headers' => array(),
);
$options['headers'] += array(
'NodejsServiceKey' => self::$config['serviceKey'],
'Content-type' => 'application/json',
);
$response = drupal_http_request(self::$baseUrl . $url, $options);
// If a http error occurred, and logging of http errors is enabled, log it.
if (isset($response->error)) {
if (self::$config['log_http_errors']) {
$params = array(
'%code' => $response->code,
'%error' => $response->error,
'%url' => $url,
);
$log_message = 'Error reaching the Node.js server at "%url": [%code] %error.';
if (!empty($options['data'])) {
$params['data'] = $options['data'];
$log_message = 'Error reaching the Node.js server at "%url" with data "%data": [%code] %error.';
}
watchdog('nodejs', $log_message, $params);
}
return FALSE;
}
// No errors, so return Node.js server response.
return json_decode($response->data);
}