Add non-caching headers to Response class

This commit is contained in:
Robbie Antenesse 2018-01-04 22:07:00 -07:00
parent adf3e3fc18
commit b5c60c7b5c
1 changed files with 10 additions and 1 deletions

View File

@ -1,13 +1,22 @@
<?php <?php
class Response { class Response {
private static function defaultHeaders () {
header('Expires: Sun, 01 Nov 2015 22:46:51 GMT');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
public static function json ($data, $http_code = 200) { public static function json ($data, $http_code = 200) {
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
Response::defaultHeaders();
http_response_code($http_code); http_response_code($http_code);
echo json_encode($data); echo json_encode($data);
} }
public static function html ($html, $http_code = 200) { public static function html ($html, $http_code = 200) {
header('Content-Type: text/html; charset=utf-8'); header('Content-Type: text/html; charset=utf-8');
Response::defaultHeaders();
http_response_code($http_code); http_response_code($http_code);
echo $html; echo $html;
} }