1
0

download.go 866 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package imagedata
  2. import (
  3. "net/http"
  4. "github.com/imgproxy/imgproxy/v3/ierrors"
  5. "github.com/imgproxy/imgproxy/v3/imagefetcher"
  6. "github.com/imgproxy/imgproxy/v3/transport"
  7. )
  8. var (
  9. Fetcher *imagefetcher.Fetcher
  10. // For tests. This needs to move to fetcher once we will have a way to isolate
  11. // the fetcher in tests.
  12. redirectAllRequestsTo string
  13. )
  14. type DownloadOptions struct {
  15. Header http.Header
  16. CookieJar http.CookieJar
  17. }
  18. func initDownloading() error {
  19. ts, err := transport.NewTransport()
  20. if err != nil {
  21. return err
  22. }
  23. Fetcher, err = imagefetcher.NewFetcher(ts, imagefetcher.NewConfigFromEnv())
  24. if err != nil {
  25. return ierrors.Wrap(err, 0, ierrors.WithPrefix("can't create image fetcher"))
  26. }
  27. return nil
  28. }
  29. func RedirectAllRequestsTo(u string) {
  30. redirectAllRequestsTo = u
  31. }
  32. func StopRedirectingRequests() {
  33. redirectAllRequestsTo = ""
  34. }