Skip to content

Commit 173e26c

Browse files
committed
Proxy now requires CURL extension
1 parent 21d684c commit 173e26c

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- host and proxy parameter have to be set before calling geocode(). Values are now
55
stricter. In the last 30 days no customer used either option.
66
- Explicitly enforce SSL certificate verification in both CURL and fopen.
7-
- Add proxy support to fopen fallback
7+
- Proxy now requires CURL extension; raises explicit error with fopen fallback
88
- Fix stream context not being passed to file_get_contents
99

1010
3.3.4 -- Mon Dec 15 2025

src/AbstractGeocoder.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ protected function getJSON($query)
8383
$ret = $this->getJSONByCurl($query);
8484
return $ret;
8585
} elseif (ini_get('allow_url_fopen')) {
86+
if ($this->proxy) {
87+
throw new \Exception('Proxy support requires the CURL extension');
88+
}
8689
$ret = $this->getJSONByFopen($query);
8790
return $ret;
8891
} else {
@@ -92,18 +95,12 @@ protected function getJSON($query)
9295

9396
protected function getJSONByFopen($query)
9497
{
95-
$httpOptions = [
96-
'user_agent' => $this->user_agent,
97-
'timeout' => $this->timeout
98-
];
99-
if ($this->proxy) {
100-
$httpOptions['proxy'] = $this->proxy;
101-
$httpOptions['request_fulluri'] = true;
102-
}
103-
10498
$context = stream_context_create(
10599
[
106-
'http' => $httpOptions,
100+
'http' => [
101+
'user_agent' => $this->user_agent,
102+
'timeout' => $this->timeout
103+
],
107104
'ssl' => [
108105
'verify_peer' => true,
109106
'verify_peer_name' => true

tests/GeocoderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ public function testProxy()
8383
}
8484
// https://opencagedata.com/api#testingkeys
8585
$geocoder = new Geocoder('6d0e711d72d74daeb2b0bfd2a5cdfdba');
86-
$geocoder->setProxy($proxy);
86+
try {
87+
$geocoder->setProxy($proxy);
88+
} catch (\Exception $e) {
89+
$this->markTestSkipped('PROXY environment variable is not a valid proxy URL: ' . $proxy);
90+
}
8791
$query = "82 Clerkenwell Road, London";
8892
$result = $geocoder->geocode($query);
8993

0 commit comments

Comments
 (0)