CORS Headers for updates.drupal.org

Created on 28 January 2024, about 1 year ago

Problem/Motivation

I'm running Drupal 7 under php-wasm in the browser, and I've implemented a custom HTTP request function. The issue I'm having is that when a request is made to https://updates.drupal.org/... URLs, there are no CORS headers on the response, so the request fails.

$conf['drupal_http_request_function'] = 'vrzno_http_request';

function vrzno_http_request($url, array $options = array()) {
  $uri = @parse_url($url);

  $result = new stdClass();

  if ($uri == FALSE) {
    $result->error = 'unable to parse URL';
    $result->code = -1001;
    return $result;
  }

  // Merge the default options.
  $options += array(
    'headers' => array(),
    'method' => 'GET',
    'data' => NULL,
    'max_redirects' => 3,
    'timeout' => 30.0,
    'context' => NULL,
    'scheme' => 'http',
  );

  // Merge the default headers.
  $options['headers'] += array(
    'User-Agent' => 'Drupal (+http://drupal.org/)',
  );

  $request = (new Vrzno)->fetch($url, (object)[
    'headers' => (object) $options['headers'],
    'method'  => $options['method'],
  ]);

  $response = vrzno_await($request);
  $content  = vrzno_await($response->text());

  $result->data = $content;
  $result->code = 200;

  return $result;
}


Steps to reproduce

1) Make a request to https://updates.drupal.org/... or any other URL on that API

2) Observe that there are currently no CORS headers on the response.

Proposed resolution

The resolution would have the following headers to the response:

Access-Control-Allow-Headers: *
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, HEAD, OPTIONS

Remaining tasks

Just the headers, please.

User interface changes

None.

API changes

CORS headers to allow any origin to access https://updates.drupal.org/... URLs.

Data model changes

None.

✨ Feature request
Status

Active

Component

Development Environments

Created by

πŸ‡ΊπŸ‡ΈUnited States seanmorris227

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @seanmorris227
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    This will impact the trial experience for Starshot, as it'll be running in Wams and use vrzno to make HTTP requests via JavaScript from PHP code

  • πŸ‡ΊπŸ‡ΈUnited States dww

    I believe this is a more appropriate component for this request...

    +1 subscribe πŸ˜‚ (inside joke for truly old-timers).

Production build 0.71.5 2024