ruleset.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Package ruleset provides the basics rules which are being extended by rules.
  2. package ruleset
  3. // The shared header-mostly rules for both nethttp and fasthttp
  4. var (
  5. AuthorizationRule = func(header GetHeader) bool {
  6. return header("Authorization") == "" &&
  7. header("Proxy-Authenticate") == ""
  8. }
  9. MustRevalidateRule = func(header GetHeader) bool {
  10. return header("Must-Revalidate") == ""
  11. }
  12. ZeroMaxAgeRule = func(header GetHeader) bool {
  13. return header("S-Maxage") != "0" &&
  14. header("Max-Age") != "0"
  15. }
  16. NoCacheRule = func(header GetHeader) bool {
  17. return header("No-Cache") != "true"
  18. }
  19. )
  20. // THESE ARE HERE BECAUSE THE GOLANG DOESN'T SUPPORTS THE F.... INTERFACE ALIAS, THIS SHOULD EXISTS ONLY ON /$package/rule
  21. // or somehow move interface generic rules (such as conditional, header) here, because the code sharing is exactly THE SAME
  22. // except the -end interface, this on other language can be designing very very nice but here no OOP so we stuck on this,
  23. // it's better than before but not as I wanted to be.
  24. // They will make me to forget my software design skills,
  25. // they (the language's designers) rollback the feature of type alias, BLOG POSTING that is an UNUSEFUL feature.....
  26. // GetHeader is a type of func which receives a func of string which returns a string
  27. // used to get headers values, both request's and response's.
  28. type GetHeader func(string) string
  29. // HeaderPredicate is a type of func which receives a func of string which returns a string and a boolean,
  30. // used to get headers values, both request's and response's.
  31. type HeaderPredicate func(GetHeader) bool
  32. // EmptyHeaderPredicate returns always true
  33. var EmptyHeaderPredicate = func(GetHeader) bool {
  34. return true
  35. }