You are here

function background_process_build_request in Background Process 6

Same name and namespace in other branches
  1. 8 background_process.module \background_process_build_request()
  2. 7.2 background_process.http.inc \background_process_build_request()
  3. 7 background_process.module \background_process_build_request()

Build url and headers for http request

Parameters

$url: Relative url for the request

$service_hostname: Name of service host, e.g. 'default'

Return value

array array(url, headers)

4 calls to background_process_build_request()
BackgroundProcess::dispatch in ./BackgroundProcess.class.php
background_process_ass_auto_unlock in background_process_ass/background_process_ass.module
Unlock locked processes that aren't really running.
background_process_ass_get_server_status in background_process_ass/background_process_ass.module
Get apache extended server status.
background_process_determine_default_service_host in ./background_process.module
Determine host for current installation. Host is determined in the following order: <server name> <localhost> <server ip>

File

./background_process.module, line 911

Code

function background_process_build_request($url, $service_hostname = NULL, $options = array()) {
  $service_hosts = background_process_get_service_hosts();
  if (!$service_hostname || empty($service_hosts[$service_hostname])) {
    $service_hostname = 'default';
  }
  $service_host = $service_hosts[$service_hostname];
  $options += array(
    'absolute' => TRUE,
    'base_url' => $service_host['base_url'],
  );
  $url = url($url, $options);
  $parsed = parse_url($url);
  $host = !empty($service_host['http_host']) ? $service_host['http_host'] : (isset($parsed['host']) ? $parsed['host'] : NULL);
  $headers = _background_process_request_headers();
  $headers = _background_process_filter_headers($headers);
  $headers['Host'] = $host;
  $headers['Connection'] = 'close';
  if (isset($parsed['user'])) {
    $headers['Authorization'] = 'Basic ' . base64_encode($parsed['user'] . ':' . $parsed['pass']);
  }
  return array(
    $url,
    $headers,
  );
}