Ver Fonte

dev 2020-10

Max F há 5 anos atrás
pai
commit
15c87c2529

+ 9 - 2
src/App/Response.php

@@ -137,7 +137,12 @@ class Response
 	public function sendHeaders()
 	{
 		if ($this->headers_sent) {
+			//error_log("Warning: headers already sent");
+			return;
+
+		} else if (headers_sent()) {
 			error_log("Warning: headers already sent");
+			$this->headers_sent = true;
 			return;
 		}
 
@@ -147,20 +152,22 @@ class Response
 			$status_name = empty($this->status_name) ? "Unknown http status" : $this->status_name;
 
 			header('HTTP/1.0 ' . $this->status . ' ' . $status_name);
-			$this->headers['Status'] = 'HTTP/1.0 ' . $this->status . ' ' . $status_name;
 
-			$this->headers['X-Status'] = $this->status;
+			$this->headers['X-Status'] = $this->status . ' ' . $status_name;
 		}
 
 		if (empty($this->headers['Content-Type']) && ! empty($this->content_type)) {
 			$this->headers['Content-Type'] = $this->content_type;
 		}
+
 		if (empty($this->headers['Content-Length'])) {
 			$this->headers['Content-Length'] = $this->getContentLength();
 		}
+
 		foreach ($this->headers as $k => $v) {
 			header($k . ": " . $v);
 		}
+
 		$this->headers_sent = true;
 	}
 

+ 2 - 1
src/App/ResponseError.php

@@ -14,7 +14,8 @@ class ResponseError extends Response
 		parent::__construct($content, $content_type);
 
 		if (is_null($content)) {
-			$this->content = '<h1>' . $this->status_name . '</h1>';
+			$this->content  = '<title>' . $this->status . " " . $this->status_name . '</title>';
+			$this->content .= '<h1>' . $this->status . " " . $this->status_name . '</h1>';
 		}
 
 		$this->setStatus($status);

+ 1 - 1
src/App/ResponseError404.php

@@ -9,7 +9,7 @@ class ResponseError404 extends ResponseError
 	protected $status_name = 'Not Found';
 
 
-	public function __construct($content='', $content_type='text/html')
+	public function __construct($content=null, $content_type='text/html')
 	{
 		parent::__construct($this->status, $content, $content_type);
 	}

+ 8 - 13
src/App/ResponseRedirect.php

@@ -13,30 +13,25 @@ class ResponseRedirect extends Response
 	{
 		parent::__construct('', null); // $content, $content_type
 
-		$this->setStatus($status)
+		$this->setStatus($status);
 		$this->url = $url;
 	}
 
+
 	public function sendHeaders()
 	{
-		if ($this->headers_sent) {
-			error_log("Warning: headers already sent");
+		if ($this->headers_sent || headers_sent()) {
+			//error_log("Warning: headers already sent");
+			$this->content = '<meta http-equiv="refresh" content="0;URL=' . htmlspecialchars($this->url) . '">';
+			//$this->content = '<script>window.location.href = "' . $this->url . '";</script>';
 			return;
 		}
 
+		$this->content = '';
+
 		$this->headers['Location'] = $this->url;
 
 		parent::sendHeaders();
 	}
 
-	public function send()
-	{
-		if ($this->headers_sent) {
-			// Warning: redirect may not work
-		}
-
-		$this->sendHeaders();
-	}
-
-
 }