Skip to content

Commit e24c080

Browse files
committed
Replace download with symfony http-client
See: https://symfony.com/doc/current/http_client.html#https-certificate
1 parent 27f256f commit e24c080

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

src/Controller/Aggregator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Aggregator
3737
'application/xml',
3838
];
3939

40+
4041
/**
4142
* Controller constructor.
4243
*

src/EntitySource.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ class EntitySource
5757
*/
5858
protected string $url;
5959

60-
/**
61-
* The SSL CA file that should be used to validate the connection.
62-
*
63-
* @var string|null
64-
*/
65-
protected ?string $sslCAFile;
66-
6760
/**
6861
* The certificate we should use to validate downloaded metadata.
6962
*
@@ -111,10 +104,6 @@ public function __construct(Aggregator $aggregator, Configuration $config)
111104
$this->aggregator = $aggregator;
112105

113106
$this->url = $config->getString('url');
114-
$this->sslCAFile = $config->getOptionalString('ssl.cafile', null);
115-
if ($this->sslCAFile === null) {
116-
$this->sslCAFile = $aggregator->getCAFile();
117-
}
118107

119108
$this->certificate = $config->getOptionalString('cert', null);
120109

@@ -134,23 +123,18 @@ private function downloadMetadata(): EntitiesDescriptor|EntityDescriptor|null
134123
Logger::debug($this->logLoc . 'Downloading metadata from ' . var_export($this->url, true));
135124
$configUtils = new Utils\Config();
136125

137-
$context = ['ssl' => []];
138-
if ($this->sslCAFile !== null) {
139-
$context['ssl']['cafile'] = $configUtils->getCertPath($this->sslCAFile);
140-
Logger::debug(
141-
$this->logLoc . 'Validating https connection against CA certificate(s) found in ' .
142-
var_export($context['ssl']['cafile'], true),
143-
);
144-
$context['ssl']['verify_peer'] = true;
145-
$context['ssl']['CN_match'] = parse_url($this->url, PHP_URL_HOST);
146-
}
126+
$httpUtils = new Utils\HTTP();
127+
$client = $httpUtils->createHttpClient();
128+
$response = $client->request('GET', $this->url);
147129

148130
try {
149-
$httpUtils = new Utils\HTTP();
150-
$data = $httpUtils->fetch($this->url, $context, false);
151-
} catch (Error\Exception $e) {
152-
Logger::error($this->logLoc . 'Unable to load metadata from ' . var_export($this->url, true));
131+
// Trigger any issues that may occur during transport
132+
$statusCode = $response->getStatusCode();
133+
} catch (TransportException $e) {
134+
Logger::error('Unable to load metadata from ' . var_export($this->url, true));
153135
return null;
136+
} finally {
137+
$data = $response->getContent();
154138
}
155139

156140
$doc = DOMDocumentFactory::create();

tests/src/Controller/AggregatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function setUp(): void
5555
'example' => [
5656
'sources' => [
5757
[
58-
'url' => 'tests/metadata/example.xml',
58+
'url' => 'file://tests/metadata/example.xml',
5959
],
6060
],
6161
],

0 commit comments

Comments
 (0)