Преглед изворни кода

Check if HTTP_ORIGIN is set

Php was complaining that I didn't check if its set.
(Strict mode issue - yep its better style anyway).
Ecconia пре 7 година
родитељ
комит
e0b5228f4d
1 измењених фајлова са 13 додато и 12 уклоњено
  1. 13 12
      middleware/CorsHeader.php

+ 13 - 12
middleware/CorsHeader.php

@@ -7,20 +7,21 @@
 	class CorsHeader {
 		public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
 
-			$method = $_SERVER['REQUEST_METHOD'];
-			$origin = $_SERVER['HTTP_ORIGIN'];
+			if(isset($_SERVER['HTTP_ORIGIN'])) {
+				$origin = $_SERVER['HTTP_ORIGIN'];
+				
+				if(in_array($origin, ['http://localhost:8080', 'https://vv.ecconia.de'])) {
+					header('Access-Control-Allow-Origin: ' . $origin);
+					header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
+					header('Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
 
-			if(in_array($origin, ['http://localhost:8080', 'https://vv.ecconia.de'])) {
-				header('Access-Control-Allow-Origin: ' . $origin);
-				header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
-				header('Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
+					if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+						header('Access-Control-Max-Age: 1728000');
+						header('Content-Type: text/plain charset=UTF-8');
+						header('Content-Length: 0');
 
-				if($method == 'OPTIONS') {
-					header('Access-Control-Max-Age: 1728000');
-					header('Content-Type: text/plain charset=UTF-8');
-					header('Content-Length: 0');
-
-					return $response->withStatus(204);
+						return $response->withStatus(204);
+					}
 				}
 			}