Vars.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package Trog::Vars;
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. =head1 Trog::Vars
  6. Constants shared between the data model, the renderer and the routes.
  7. Nothing here is computed; it's all package variables so that callers can read
  8. them directly rather than paying for a function call on every request.
  9. =head2 VARIABLES
  10. =over 4
  11. =item $CHUNK_SEP
  12. Separator used when a file upload has to be reassembled from chunks.
  13. Chosen to be something no browser will ever send us by accident.
  14. =item $CHUNK_SIZE
  15. Size of said chunks, in bytes. 1MB.
  16. =item %content_types
  17. Maps the short names used in templates and route definitions (html, json, ...)
  18. onto the Content-Type header they mean.
  19. =item %byct
  20. The reverse of %content_types, for going from a Content-Type back to the short
  21. name -- which is how the renderer picks which Trog::Renderer subclass handles a
  22. response.
  23. =item %cache_control
  24. Named Cache-Control policies. 'revalidate' for content which may have changed,
  25. 'nocache' for anything user specific, and 'static' for assets which are
  26. immutable once published.
  27. =back
  28. =cut
  29. #1MB chunks
  30. our $CHUNK_SEP = 'tCMSep666YOLO42069';
  31. our $CHUNK_SIZE = 1024000;
  32. our %content_types = (
  33. text => "text/plain",
  34. html => "text/html",
  35. json => "application/json",
  36. blob => "application/octet-stream",
  37. xml => "text/xml",
  38. xsl => "text/xsl",
  39. css => "text/css",
  40. rss => "application/rss+xml",
  41. email => "multipart/related",
  42. );
  43. our %byct = reverse %Trog::Vars::content_types;
  44. our %cache_control = (
  45. revalidate => "no-cache, max-age=0",
  46. nocache => "no-store",
  47. static => "public, max-age=604800, immutable",
  48. );
  49. # NOTE: the post schema and its validators used to be duplicated here as well
  50. # as in Trog::DataModule, and filter() had no callers at all. Both are gone --
  51. # a post's shape is now an OpenAPIv3 schema, see Trog::DataModule::schema_for().
  52. 1;