Skip to content

Commit ad95f39

Browse files
Merge 'minor-next' into 'major-next'
Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/14233077278
2 parents 9af3cde + 673b39e commit ad95f39

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

src/utils/Internet.php

+22-27
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
use pocketmine\VersionInfo;
2727
use function array_merge;
28-
use function curl_close;
2928
use function curl_error;
3029
use function curl_exec;
3130
use function curl_getinfo;
@@ -217,34 +216,30 @@ public static function simpleCurl(string $page, float $timeout = 10, array $extr
217216
CURLOPT_HTTPHEADER => array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 " . VersionInfo::NAME . "/" . VersionInfo::VERSION()->getFullVersion(true)], $extraHeaders),
218217
CURLOPT_HEADER => true
219218
]);
220-
try{
221-
$raw = curl_exec($ch);
222-
if($raw === false){
223-
throw new InternetException(curl_error($ch));
224-
}
225-
if(!is_string($raw)) throw new AssumptionFailedError("curl_exec() should return string|false when CURLOPT_RETURNTRANSFER is set");
226-
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
227-
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
228-
$rawHeaders = substr($raw, 0, $headerSize);
229-
$body = substr($raw, $headerSize);
230-
$headers = [];
231-
//TODO: explore if we can set these limits lower
232-
foreach(explode("\r\n\r\n", $rawHeaders, limit: PHP_INT_MAX) as $rawHeaderGroup){
233-
$headerGroup = [];
234-
foreach(explode("\r\n", $rawHeaderGroup, limit: PHP_INT_MAX) as $line){
235-
$nameValue = explode(":", $line, 2);
236-
if(isset($nameValue[1])){
237-
$headerGroup[trim(strtolower($nameValue[0]))] = trim($nameValue[1]);
238-
}
219+
$raw = curl_exec($ch);
220+
if($raw === false){
221+
throw new InternetException(curl_error($ch));
222+
}
223+
if(!is_string($raw)) throw new AssumptionFailedError("curl_exec() should return string|false when CURLOPT_RETURNTRANSFER is set");
224+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
225+
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
226+
$rawHeaders = substr($raw, 0, $headerSize);
227+
$body = substr($raw, $headerSize);
228+
$headers = [];
229+
//TODO: explore if we can set these limits lower
230+
foreach(explode("\r\n\r\n", $rawHeaders, limit: PHP_INT_MAX) as $rawHeaderGroup){
231+
$headerGroup = [];
232+
foreach(explode("\r\n", $rawHeaderGroup, limit: PHP_INT_MAX) as $line){
233+
$nameValue = explode(":", $line, 2);
234+
if(isset($nameValue[1])){
235+
$headerGroup[trim(strtolower($nameValue[0]))] = trim($nameValue[1]);
239236
}
240-
$headers[] = $headerGroup;
241237
}
242-
if($onSuccess !== null){
243-
$onSuccess($ch);
244-
}
245-
return new InternetRequestResult($headers, $body, $httpCode);
246-
}finally{
247-
curl_close($ch);
238+
$headers[] = $headerGroup;
239+
}
240+
if($onSuccess !== null){
241+
$onSuccess($ch);
248242
}
243+
return new InternetRequestResult($headers, $body, $httpCode);
249244
}
250245
}

0 commit comments

Comments
 (0)