Vars.pm 1.8 KB

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