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.