From 2864f66377c43792744f01c33ef11333daefd077 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 31 Aug 2020 15:43:18 +0000 Subject: [PATCH] i forgot about HEAD existing --- pages/blog.php | 3 +++ pages/contact.php | 4 ++++ pages/etcetera.php | 4 ++++ pages/index.php | 10 ++++++++++ pages/projects.php | 2 ++ pages/related.php | 2 ++ public/index.php | 22 +++++++++++++++------- 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/pages/blog.php b/pages/blog.php index ea3bf80..d8ee6c9 100644 --- a/pages/blog.php +++ b/pages/blog.php @@ -12,6 +12,9 @@ if($reqPath === '/blog-elements.json') { header('Content-Type: application/json; charset=utf-8'); + if($reqHead) + return FM_HIT; + $title = filter_input(INPUT_GET, 'title', FILTER_SANITIZE_STRING); ob_start(); diff --git a/pages/contact.php b/pages/contact.php index 3ec5b6c..dc66b78 100644 --- a/pages/contact.php +++ b/pages/contact.php @@ -17,6 +17,8 @@ if($reqPath === '/now-listening.json') { if($reqMethod !== 'GET') return FM_ERR | 405; header('Content-Type: application/json; charset=utf-8'); + if($reqHead) + return FM_HIT; $lfmInfo = cache_output('lastfm', 10, function() { return json_decode(file_get_contents('https://now.flash.moe/get.php?u=flashwave_')); @@ -44,6 +46,8 @@ if($reqPath === '/now-listening.json') { if($reqPath === '/contact') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; $contact = [ [ diff --git a/pages/etcetera.php b/pages/etcetera.php index 1e29d5c..a7338a8 100644 --- a/pages/etcetera.php +++ b/pages/etcetera.php @@ -9,6 +9,10 @@ if($reqPath === '/etc.php' || $reqPath === 'etc.html' } if($reqPath === '/etc') { + if($reqMethod !== 'GET') + return FM_ERR | 405; + if($reqHead) + return FM_HIT; $links = [ [ 'title' => 'ASCII Table', diff --git a/pages/index.php b/pages/index.php index 4e49076..dcb07d9 100644 --- a/pages/index.php +++ b/pages/index.php @@ -12,6 +12,8 @@ if($reqPath === '/header-bgs.json') { return FM_ERR | 405; header('Content-Type: application/json; charset=utf-8'); + if($reqHead) + return FM_HIT; echo json_encode(FM_BGS); return FM_HIT; @@ -20,6 +22,8 @@ if($reqPath === '/header-bgs.json') { if($reqPath === '/now-listening') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; $offset = (int)filter_input(INPUT_GET, 'offset', FILTER_SANITIZE_NUMBER_INT); @@ -41,6 +45,8 @@ if($reqPath === '/now-listening') { if($reqPath === '/home') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; fm_component('header', [ 'title' => 'flash.moe / homepage', @@ -86,6 +92,8 @@ if($reqPath === '/home') { if($reqPath === '/test') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; header('Content-Type: text/plain'); @@ -97,6 +105,8 @@ if($reqPath === '/test') { if($reqPath === '/') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; $legacyPage = filter_input(INPUT_GET, 'p', FILTER_SANITIZE_STRING); if(!empty($legacyPage)) { diff --git a/pages/projects.php b/pages/projects.php index 5823716..044a005 100644 --- a/pages/projects.php +++ b/pages/projects.php @@ -10,6 +10,8 @@ if($reqPath === '/projects.php' || $reqPath === '/projects.html' if($reqPath === '/projects') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; $projInfo = cache_output('projects', 300, function() { return json_decode(file_get_contents('https://flash.moe/2020/projects.php?dump_that_shit')); diff --git a/pages/related.php b/pages/related.php index f102b07..5184aa1 100644 --- a/pages/related.php +++ b/pages/related.php @@ -10,6 +10,8 @@ if($reqPath === '/related.php' || $reqPath === '/related.html' if($reqPath === '/related') { if($reqMethod !== 'GET') return FM_ERR | 405; + if($reqHead) + return FM_HIT; $related = [ [ diff --git a/public/index.php b/public/index.php index 9be5170..43e135c 100644 --- a/public/index.php +++ b/public/index.php @@ -122,6 +122,12 @@ ob_start(); $reqMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING); $reqPath = '/' . trim(parse_url(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING), PHP_URL_PATH), '/'); +$reqHead = false; + +if($reqMethod == 'HEAD') { + $reqMethod = 'GET'; + $reqHead = true; +} if(substr($reqPath, 0, 7) === '/error/') { $statusCode = intval(substr($reqPath, 7, 3)); @@ -142,12 +148,14 @@ if(substr($reqPath, 0, 7) === '/error/') { $errorInfo = FM_ERRS[$statusCode ?? 404] ?? FM_ERRS[404]; http_response_code($errorInfo['code']); -fm_component('header', ['title' => $errorInfo['title']]); +if(!$reqHead) { + fm_component('header', ['title' => $errorInfo['title']]); ?> -
-

- <?=$errorInfo['image'];?> -
-
+
+

+ <?=$errorInfo['image'];?> +
+