You are here

function background_process_build_request in Background Process 8

Same name and namespace in other branches
  1. 6 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()

Implements to Build url and headers for http request.

4 calls to background_process_build_request()
BackgroundProcess::dispatch in ./background_process.class.php
Implements to Dispatch Process.
background_process_ass_auto_unlock in background_process_ass/background_process_ass.module
Implements to 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
Implements to Determine host for current installation.

File

./background_process.module, line 839
This module implements a framework for calling funtions in the background.

Code

function background_process_build_request($url, $service_hostname = NULL, $options = []) {
  $service_hosts = background_process_get_service_hosts();
  if (!$service_hostname || empty($service_hosts[$service_hostname])) {
    $service_hostname = 'default';
  }
  $options += [
    'absolute' => TRUE,
    'base_url' => $service_hosts,
  ];
  $url = $service_hosts . '/' . $url;
  $parsed = parse_url($url);
  $host = !empty($service_hosts['http_host']) ? $service_hosts['http_host'] : (isset($parsed['host']) ? isset($parsed['port']) ? $parsed['host'] . ':' . $parsed['port'] : $parsed['host'] : NULL);
  $headers = _background_process_request_headers();
  $headers = _background_process_filter_headers($headers);
  $headers['User-Agent'] = \Drupal::config('background_process.settings')
    ->get('background_process_user_agent');
  $headers['Host'] = $host;
  $headers['Connection'] = 'close';
  if (isset($parsed['user'])) {
    $headers['Authorization'] = 'Basic ' . base64_encode($parsed['user'] . ':' . $parsed['pass']);
  }
  return [
    $url,
    $headers,
  ];
}