Skip to content

Commit

Permalink
fix(files): file service now sends 304 and 403 headers more reliably
Browse files Browse the repository at this point in the history
File service now checks if file has been deleted or modified before sending 304 headers.

File service now strips -gzip suffixes from headers to send correct 304 headers for
deflated file types.

Fixes #9571
  • Loading branch information
hypeJunction committed Mar 28, 2016
1 parent 75d0b1e commit c9af179
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions engine/classes/Elgg/Application/ServeFileHandler.php
Expand Up @@ -62,12 +62,6 @@ public function getResponse(Request $request) {
return $response->setStatusCode(403)->setContent('URL has expired'); return $response->setStatusCode(403)->setContent('URL has expired');
} }


$etag = '"' . $last_updated . '"';
$response->setPublic()->setEtag($etag);
if ($response->isNotModified($request)) {
return $response;
}

$hmac_data = array( $hmac_data = array(
'expires' => (int) $expires, 'expires' => (int) $expires,
'last_updated' => (int) $last_updated, 'last_updated' => (int) $last_updated,
Expand Down Expand Up @@ -97,6 +91,18 @@ public function getResponse(Request $request) {
return $response->setStatusCode(403)->setContent('URL has expired'); return $response->setStatusCode(403)->setContent('URL has expired');
} }


$if_none_match = $request->headers->get('if_none_match');
if (!empty($if_none_match)) {
// strip mod_deflate suffixes
$request->headers->set('if_none_match', str_replace('-gzip', '', $if_none_match));
}

$etag = '"' . $last_updated . '"';
$response->setPublic()->setEtag($etag);
if ($response->isNotModified($request)) {
return $response;
}

$public = $use_cookie ? false : true; $public = $use_cookie ? false : true;
$content_disposition = $disposition == 'i' ? 'inline' : 'attachment'; $content_disposition = $disposition == 'i' ? 'inline' : 'attachment';


Expand Down Expand Up @@ -127,4 +133,5 @@ private function getCookieValue(Request $request) {
$session_name = $config['session']['name']; $session_name = $config['session']['name'];
return $request->cookies->get($session_name, ''); return $request->cookies->get($session_name, '');
} }

} }

0 comments on commit c9af179

Please sign in to comment.