Skip to content

Commit

Permalink
Merge pull request #4 from xlecours/adding_images_etag_header
Browse files Browse the repository at this point in the history
Adding Etag headers for /candidates/visits/images/Image.php
  • Loading branch information
cmadjar authored Apr 24, 2019
2 parents e5a0fee + 5e2238e commit 8fb5b64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion htdocs/api/v0.0.3-dev/APIBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ function handleRequest()
case 'PATCH':
$this->handlePATCH();
break;

case 'HEAD':
$this->handleHEAD();
break;
}
}

Expand Down Expand Up @@ -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
*
Expand Down
4 changes: 3 additions & 1 deletion htdocs/api/v0.0.3-dev/candidates/visits/images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct($method, $CandID, $VisitLabel, $Filename)
if (empty($this->AllowedMethods)) {
$this->AllowedMethods = [
'GET',
'HEAD',
];
}
$this->CandID = $CandID;
Expand Down Expand Up @@ -143,7 +144,8 @@ protected function getHeader($headerName)
*/
public function calculateETag()
{
return null;
$filename = $this->getFullPath();
return hash_file('md5', $filename);
}

/**
Expand Down

0 comments on commit 8fb5b64

Please sign in to comment.