config.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package headerwriter
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. )
  5. // Config is the package-local configuration
  6. type Config struct {
  7. // SetCanonicalHeader indicates whether to set the canonical header
  8. SetCanonicalHeader bool
  9. // TTL is the default Cache-Control max-age= value for cached images
  10. DefaultTTL int
  11. // CacheControlPassthrough indicates whether to passthrough the Cache-Control header
  12. // from the original response
  13. CacheControlPassthrough bool
  14. // LastModifiedEnabled indicates whether to set the Last-Modified header
  15. LastModifiedEnabled bool
  16. // EnableClientHints indicates whether to enable Client Hints in Vary header
  17. EnableClientHints bool
  18. // SetVaryAccept indicates that the Vary header should include Accept
  19. SetVaryAccept bool
  20. }
  21. // NewConfigFromEnv creates a new Config instance from the current configuration
  22. func NewConfigFromEnv() *Config {
  23. return &Config{
  24. SetCanonicalHeader: config.SetCanonicalHeader,
  25. DefaultTTL: config.TTL,
  26. LastModifiedEnabled: config.LastModifiedEnabled,
  27. CacheControlPassthrough: config.CacheControlPassthrough,
  28. EnableClientHints: config.EnableClientHints,
  29. SetVaryAccept: config.AutoWebp ||
  30. config.EnforceWebp ||
  31. config.AutoAvif ||
  32. config.EnforceAvif ||
  33. config.AutoJxl ||
  34. config.EnforceJxl,
  35. }
  36. }