Skip to content

Commit 29d58da

Browse files
committed
Review 👾
1 parent 513d7cb commit 29d58da

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

‎src/Drivers/StreamDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function exec($url, &$httpStatus, &$contentType, &$errorCode, &$errorMess
9696

9797
$handle = fopen($url, 'rb', false, $this->context);
9898

99-
if (!$handle) {
99+
if ($handle === false) {
100100
$err = error_get_last();
101101
$errorCode = $err['type'];
102102
$errorMessage = $err['message'];

‎src/Proxy.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function setTemporary($path)
282282

283283
$temp = fopen($path, 'rb+');
284284

285-
if (!$temp) {
285+
if ($temp === false) {
286286
$this->raise('Failed to open: ' . $path);
287287
}
288288

@@ -361,7 +361,7 @@ public function download($url)
361361

362362
$this->contentType = $contentType;
363363

364-
if ($httpStatus < 200 || $httpStatus >= 300) {
364+
if ($httpStatus !== null && ($httpStatus < 200 || $httpStatus >= 300)) {
365365
$success = false;
366366

367367
$this->errorCode = $httpStatus;
@@ -413,13 +413,7 @@ public function response()
413413
$this->raise('No downloads yet');
414414
}
415415

416-
header('Access-Control-Allow-Headers: *');
417-
header('Access-Control-Allow-Methods: OPTIONS, GET');
418-
header('Access-Control-Allow-Origin: *');
419-
header('Access-Control-Request-Method: *');
420-
header('Content-type: ' . $this->contentType);
421-
422-
$this->httpCache();
416+
$this->sendHeaders($this->contentType);
423417

424418
$handle = $this->temporary;
425419

@@ -444,9 +438,7 @@ public function jsonp($callback)
444438
$this->raise('No downloads yet');
445439
}
446440

447-
header('Content-type: application/javascript');
448-
449-
$this->httpCache();
441+
$this->sendHeaders('application/javascript');
450442

451443
$contentType = $this->contentType;
452444
$extra = null;
@@ -539,8 +531,13 @@ private function refreshOptions()
539531
$this->options['update'] += 1;
540532
}
541533

542-
private function httpCache()
534+
private function sendHeaders($contentType)
543535
{
536+
header('Access-Control-Allow-Headers: *');
537+
header('Access-Control-Allow-Methods: OPTIONS, GET');
538+
header('Access-Control-Allow-Origin: *');
539+
header('Access-Control-Request-Method: *');
540+
544541
$seconds = $this->responseCacheTime;
545542

546543
if ($seconds > 0) {
@@ -558,6 +555,7 @@ private function httpCache()
558555
}
559556

560557
header('Expires: ' . $datetime .' GMT');
558+
header('Content-type: ' . $contentType);
561559
}
562560

563561
private function validateUrl($url)
@@ -573,10 +571,10 @@ private function validateUrl($url)
573571
'\\|' => '|'
574572
));
575573

576-
$this->allowedUrlsRegEx = '#^(' . $regex . ')#i';
574+
$this->allowedUrlsRegEx = '#^(' . $regex . ')#';
577575
}
578576

579-
if (!preg_match($this->allowedUrlsRegEx, $url)) {
577+
if (preg_match($this->allowedUrlsRegEx, $url) !== 1) {
580578
return false;
581579
}
582580
}

0 commit comments

Comments
 (0)