download.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package imagedata
  2. var (
  3. // Fetcher *imagefetcher.Fetcher
  4. // downloader *imagedownloader.Downloader
  5. // For tests
  6. // redirectAllRequestsTo string
  7. )
  8. // type DownloadOptions struct {
  9. // Header http.Header
  10. // CookieJar http.CookieJar
  11. // }
  12. // func initDownloading() error {
  13. // ts, err := transport.NewTransport()
  14. // if err != nil {
  15. // return err
  16. // }
  17. // Fetcher, err = imagefetcher.NewFetcher(ts, imagefetcher.NewConfigFromEnv())
  18. // if err != nil {
  19. // return ierrors.Wrap(err, 0, ierrors.WithPrefix("can't create image fetcher"))
  20. // }
  21. // downloader = imagedownloader.NewDownloader(Fetcher)
  22. // return nil
  23. // }
  24. // func download(ctx context.Context, imageURL string, opts DownloadOptions, secopts security.Options) (imagedatanew.ImageData, error) {
  25. // // We use this for testing
  26. // if len(redirectAllRequestsTo) > 0 {
  27. // imageURL = redirectAllRequestsTo
  28. // }
  29. // return downloader.Download(ctx, imageURL, imagedownloader.DownloadOptions{
  30. // Header: opts.Header,
  31. // CookieJar: opts.CookieJar,
  32. // }, secopts)
  33. // }
  34. // func RedirectAllRequestsTo(u string) {
  35. // redirectAllRequestsTo = u
  36. // }
  37. // func StopRedirectingRequests() {
  38. // redirectAllRequestsTo = ""
  39. // }