Commit 92d70087 authored by Katherine Senzee's avatar Katherine Senzee Committed by Stephen Mustgrave
Browse files

Issue #3385745 by ksenzee: The proxy_headers feature is missing from 2.0.x and 2.1.x

parent b57c9689
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,5 +2,6 @@ hotlink: false
origin: ''
origin_dir: ''
use_imagecache_root: true
proxy_headers: ''
verify: true
excluded_extensions: ''
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ stage_file_proxy.settings:
    origin_dir:
      type: string
      label: "Origin dir"
    proxy_headers:
      type: string
      label: "Proxy headers"
    use_imagecache_root:
      type: boolean
      label: "Use imagecache root"
+18 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ class ProxySubscriber implements EventSubscriberInterface {
      $query_parameters = UrlHelper::filterQueryParameters($query);
      $options = [
        'verify' => $config->get('verify'),
        'headers' => $this->createProxyHeadersArray($config->get('proxy_headers')),
      ];

      if ($config->get('hotlink')) {
@@ -224,4 +225,21 @@ class ProxySubscriber implements EventSubscriberInterface {
    return $events;
  }

  /**
   * Helper function to generate HTTP headers array
   *
   * @param $headers_string
   * @return array
   */
  protected function createProxyHeadersArray($headers_string) {
    $lines = explode("\n", $headers_string);
    $headers = [];
    foreach ($lines as $line) {
      $header = explode('|', $line);
      if (count ($header) > 1) {
        $headers[$header[0]] = $header[1];
      }
    }
    return $headers;
  }
}
+14 −0
Original line number Diff line number Diff line
@@ -133,6 +133,19 @@ class SettingsForm extends ConfigFormBase {
      ],
    ];

    $form['proxy_headers'] = [
      '#type' => 'textarea',
      '#title' => $this->t('HTTP headers'),
      '#default_value' => $config->get('proxy_headers'),
      '#description' => $this->t('When Stage File Proxy is configured to transfer the
        remote file to local machine, it will use this headers for HTTP request.
        Use format like "Referer|http://example.com/'),
      '#required' => FALSE,
      '#config' => [
        'key' => 'stage_file_proxy.settings:proxy_headers'
      ],
    ];

    return parent::buildForm($form, $form_state);
  }

@@ -161,6 +174,7 @@ class SettingsForm extends ConfigFormBase {
      'hotlink',
      'verify',
      'excluded_extensions',
      'proxy_headers',
    ];
    foreach ($keys as $key) {
      $value = $form_state->getValue($key);
+8 −0
Original line number Diff line number Diff line
@@ -21,3 +21,11 @@ function stage_file_proxy_update_8002() {
    $config->set('origin_dir', '')->save();
  }
}

/**
 * Add new schema option proxy_headers.
 */
function stage_file_proxy_update_8003() {
  $config = \Drupal::configFactory()->getEditable('stage_file_proxy.settings');
  $config->set('proxy_headers', '')->save();
}