From 3031fa406db44e6acf63ef176af359c20254466a Mon Sep 17 00:00:00 2001
From: logmanoriginal <logmanoriginal@users.noreply.github.com>
Date: Mon, 5 Nov 2018 19:28:47 +0100
Subject: [PATCH] core: Set code in header() instead of calling
 http_response_code()

---
 bridges/FacebookBridge.php |  3 +--
 index.php                  | 11 ++++-------
 lib/Authentication.php     |  3 +--
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php
index 73bc84df..5e3f96b6 100644
--- a/bridges/FacebookBridge.php
+++ b/bridges/FacebookBridge.php
@@ -426,8 +426,7 @@ class FacebookBridge extends BridgeAbstract {
 		// Show captcha filling form to the viewer, proxying the captcha image
 		$img = base64_encode(getContents($captcha->find('img', 0)->src));
 
-		http_response_code(500);
-		header('Content-Type: text/html');
+		header('Content-Type: text/html', true, 500);
 
 		$message = <<<EOD
 <form method="post" action="?{$_SERVER['QUERY_STRING']}">
diff --git a/index.php b/index.php
index 6d11346c..0bafbf7d 100644
--- a/index.php
+++ b/index.php
@@ -240,7 +240,7 @@ try {
 				$stime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
 
 				if($mtime <= $stime) { // Cached data is older or same
-					header('HTTP/1.1 304 Not Modified');
+					header('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $mtime) . 'GMT', true, 304);
 					die();
 				}
 			}
@@ -317,13 +317,11 @@ try {
 			$format->display();
 		} catch(Error $e) {
 			error_log($e);
-			http_response_code($e->getCode());
-			header('Content-Type: text/html');
+			header('Content-Type: text/html', true, $e->getCode());
 			die(buildTransformException($e, $bridge));
 		} catch(Exception $e) {
 			error_log($e);
-			http_response_code($e->getCode());
-			header('Content-Type: text/html');
+			header('Content-Type: text/html', true, $e->getCode());
 			die(buildTransformException($e, $bridge));
 		}
 	} else {
@@ -331,8 +329,7 @@ try {
 	}
 } catch(HttpException $e) {
 	error_log($e);
-	http_response_code($e->getCode());
-	header('Content-Type: text/plain');
+	header('Content-Type: text/plain', true, $e->getCode());
 	die($e->getMessage());
 } catch(\Exception $e) {
 	error_log($e);
diff --git a/lib/Authentication.php b/lib/Authentication.php
index dc75d28e..da247630 100644
--- a/lib/Authentication.php
+++ b/lib/Authentication.php
@@ -5,8 +5,7 @@ class Authentication {
 
 		if(Configuration::getConfig('authentication', 'enable') === true) {
 			if(!Authentication::verifyPrompt()) {
-				header('WWW-Authenticate: Basic realm="RSS-Bridge"');
-				header('HTTP/1.0 401 Unauthorized');
+				header('WWW-Authenticate: Basic realm="RSS-Bridge"', true, 401);
 				die('Please authenticate in order to access this instance !');
 			}