Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. function addResponseHeaders($request, $response, $ext, $modifiedTimestamp, $downloadFileName = null)
  4. {
  5. $mime = ExtToMIME::convert($ext);
  6. $headers = &$response->headers;
  7. $headers->set('Content-Type', $mime, true);
  8. $headers->set('Cache-Control', 'public', true); // TODO max-age=xxx
  9. $headers->set('Last-Modified', gmdate("D, d M Y H:i:s", $modifiedTimestamp) . " GMT", true);
  10. if ($downloadFileName != null) {
  11. $headers->set('Content-Disposition', 'filename="' . $downloadFileName . '"', true);
  12. }
  13. // note that it should be STRING
  14. $eTag = (string) $modifiedTimestamp;
  15. addRespETag($request, $response, $eTag);
  16. }
  17.  
  18. function addRespETag($request, $response, string $eTag)
  19. {
  20. $requestEtag = str_replace('"', '', $request->getETags());
  21. // Check to see if Etag has changed
  22. // strpos -> in case the browser gets `{etag}-gzip`
  23. if ($requestEtag && strpos($requestEtag[0], $eTag) === 0) {
  24. $response->setNotModified();
  25. }
  26. // Set Etag
  27. $response->setEtag($eTag);
  28. }
Add Comment
Please, Sign In to add comment