@@ -282,7 +282,7 @@ public function setTemporary($path)
282
282
283
283
$ temp = fopen ($ path , 'rb+ ' );
284
284
285
- if (! $ temp ) {
285
+ if ($ temp === false ) {
286
286
$ this ->raise ('Failed to open: ' . $ path );
287
287
}
288
288
@@ -361,7 +361,7 @@ public function download($url)
361
361
362
362
$ this ->contentType = $ contentType ;
363
363
364
- if ($ httpStatus < 200 || $ httpStatus >= 300 ) {
364
+ if ($ httpStatus !== null && ( $ httpStatus < 200 || $ httpStatus >= 300 ) ) {
365
365
$ success = false ;
366
366
367
367
$ this ->errorCode = $ httpStatus ;
@@ -413,13 +413,7 @@ public function response()
413
413
$ this ->raise ('No downloads yet ' );
414
414
}
415
415
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 );
423
417
424
418
$ handle = $ this ->temporary ;
425
419
@@ -444,9 +438,7 @@ public function jsonp($callback)
444
438
$ this ->raise ('No downloads yet ' );
445
439
}
446
440
447
- header ('Content-type: application/javascript ' );
448
-
449
- $ this ->httpCache ();
441
+ $ this ->sendHeaders ('application/javascript ' );
450
442
451
443
$ contentType = $ this ->contentType ;
452
444
$ extra = null ;
@@ -539,8 +531,13 @@ private function refreshOptions()
539
531
$ this ->options ['update ' ] += 1 ;
540
532
}
541
533
542
- private function httpCache ( )
534
+ private function sendHeaders ( $ contentType )
543
535
{
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
+
544
541
$ seconds = $ this ->responseCacheTime ;
545
542
546
543
if ($ seconds > 0 ) {
@@ -558,6 +555,7 @@ private function httpCache()
558
555
}
559
556
560
557
header ('Expires: ' . $ datetime .' GMT ' );
558
+ header ('Content-type: ' . $ contentType );
561
559
}
562
560
563
561
private function validateUrl ($ url )
@@ -573,10 +571,10 @@ private function validateUrl($url)
573
571
'\\| ' => '| '
574
572
));
575
573
576
- $ this ->allowedUrlsRegEx = '#^( ' . $ regex . ')#i ' ;
574
+ $ this ->allowedUrlsRegEx = '#^( ' . $ regex . ')# ' ;
577
575
}
578
576
579
- if (! preg_match ($ this ->allowedUrlsRegEx , $ url )) {
577
+ if (preg_match ($ this ->allowedUrlsRegEx , $ url ) !== 1 ) {
580
578
return false ;
581
579
}
582
580
}
0 commit comments