Vars.pm 1.9 KB

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