config.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package stream
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/ensure"
  4. "github.com/imgproxy/imgproxy/v3/env"
  5. "github.com/imgproxy/imgproxy/v3/httpheaders"
  6. )
  7. var (
  8. // NOTE: processing handler has the similar variable. For now, we do not want
  9. // to couple hanlders/processing and handlers/stream packages, so we duplicate it here.
  10. // Discuss.
  11. IMGPROXY_COOKIE_PASSTHROUGH = env.Describe("IMGPROXY_COOKIE_PASSTHROUGH", "boolean")
  12. )
  13. // Config represents the configuration for the image streamer
  14. type Config struct {
  15. // PassthroughRequestHeaders specifies the request headers to include in the passthrough response
  16. PassthroughRequestHeaders []string
  17. // PassthroughResponseHeaders specifies the response headers to copy from the response
  18. PassthroughResponseHeaders []string
  19. }
  20. // NewDefaultConfig returns a new Config instance with default values.
  21. func NewDefaultConfig() Config {
  22. return Config{
  23. PassthroughRequestHeaders: []string{
  24. httpheaders.IfNoneMatch,
  25. httpheaders.IfModifiedSince,
  26. httpheaders.AcceptEncoding,
  27. httpheaders.Range,
  28. },
  29. PassthroughResponseHeaders: []string{
  30. httpheaders.ContentType,
  31. httpheaders.ContentEncoding,
  32. httpheaders.ContentRange,
  33. httpheaders.AcceptRanges,
  34. httpheaders.LastModified,
  35. httpheaders.Etag,
  36. },
  37. }
  38. }
  39. // LoadConfigFromEnv loads config variables from environment
  40. func LoadConfigFromEnv(c *Config) (*Config, error) {
  41. c = ensure.Ensure(c, NewDefaultConfig)
  42. return c, nil
  43. }
  44. // Validate checks config for errors
  45. func (c *Config) Validate() error {
  46. return nil
  47. }