|
25 | 25 |
|
26 | 26 | use pocketmine\VersionInfo;
|
27 | 27 | use function array_merge;
|
28 |
| -use function curl_close; |
29 | 28 | use function curl_error;
|
30 | 29 | use function curl_exec;
|
31 | 30 | use function curl_getinfo;
|
@@ -217,34 +216,30 @@ public static function simpleCurl(string $page, float $timeout = 10, array $extr
|
217 | 216 | 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),
|
218 | 217 | CURLOPT_HEADER => true
|
219 | 218 | ]);
|
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]); |
239 | 236 | }
|
240 |
| - $headers[] = $headerGroup; |
241 | 237 | }
|
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); |
248 | 242 | }
|
| 243 | + return new InternetRequestResult($headers, $body, $httpCode); |
249 | 244 | }
|
250 | 245 | }
|
0 commit comments