From 5e2238eccfccff384b9402b77d77acc39a779bf6 Mon Sep 17 00:00:00 2001 From: xlecours Date: Wed, 24 Apr 2019 11:53:53 -0400 Subject: [PATCH] adding Etag headers for /candidates/visits/images/Image.php --- htdocs/api/v0.0.3-dev/APIBase.php | 17 ++++++++++++++++- .../candidates/visits/images/Image.php | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/htdocs/api/v0.0.3-dev/APIBase.php b/htdocs/api/v0.0.3-dev/APIBase.php index 2870f2359b1..ee204911087 100644 --- a/htdocs/api/v0.0.3-dev/APIBase.php +++ b/htdocs/api/v0.0.3-dev/APIBase.php @@ -115,7 +115,9 @@ function handleRequest() case 'PATCH': $this->handlePATCH(); break; - + case 'HEAD': + $this->handleHEAD(); + break; } } @@ -147,6 +149,19 @@ function handleETag() */ abstract function calculateETag(); + /** + * Handle a HEAD request + * + * @return void + */ + function handleHEAD() + { + $ETag = $this->calculateETag(); + $this->header("ETag: $ETag"); + $this->handleGET(); + $this->JSON = null; + } + /** * Handle a GET request * diff --git a/htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php b/htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php index fad9515c5ed..c90aadc5112 100644 --- a/htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php +++ b/htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php @@ -43,6 +43,7 @@ public function __construct($method, $CandID, $VisitLabel, $Filename) if (empty($this->AllowedMethods)) { $this->AllowedMethods = [ 'GET', + 'HEAD', ]; } $this->CandID = $CandID; @@ -143,7 +144,8 @@ protected function getHeader($headerName) */ public function calculateETag() { - return null; + $filename = $this->getFullPath(); + return hash_file('md5', $filename); } /**