config.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package stream
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. "github.com/imgproxy/imgproxy/v3/ensure"
  5. "github.com/imgproxy/imgproxy/v3/httpheaders"
  6. )
  7. // Config represents the configuration for the image streamer
  8. type Config struct {
  9. // CookiePassthrough indicates whether cookies should be passed through to the image response
  10. CookiePassthrough bool
  11. // PassthroughRequestHeaders specifies the request headers to include in the passthrough response
  12. PassthroughRequestHeaders []string
  13. // PassthroughResponseHeaders specifies the response headers to copy from the response
  14. PassthroughResponseHeaders []string
  15. }
  16. // NewDefaultConfig returns a new Config instance with default values.
  17. func NewDefaultConfig() Config {
  18. return Config{
  19. CookiePassthrough: false,
  20. PassthroughRequestHeaders: []string{
  21. httpheaders.IfNoneMatch,
  22. httpheaders.IfModifiedSince,
  23. httpheaders.AcceptEncoding,
  24. httpheaders.Range,
  25. },
  26. PassthroughResponseHeaders: []string{
  27. httpheaders.ContentType,
  28. httpheaders.ContentEncoding,
  29. httpheaders.ContentRange,
  30. httpheaders.AcceptRanges,
  31. httpheaders.LastModified,
  32. httpheaders.Etag,
  33. },
  34. }
  35. }
  36. // LoadConfigFromEnv loads config variables from environment
  37. func LoadConfigFromEnv(c *Config) (*Config, error) {
  38. c = ensure.Ensure(c, NewDefaultConfig)
  39. c.CookiePassthrough = config.CookiePassthrough
  40. return c, nil
  41. }
  42. // Validate checks config for errors
  43. func (c *Config) Validate() error {
  44. return nil
  45. }