imagefetcher -> fetcher (#1514)

This commit is contained in:
Victor Sokolov
2025-09-05 15:31:48 +02:00
committed by GitHub
parent caffdcd72b
commit 6f11d950fb
10 changed files with 29 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
package imagefetcher package fetcher
import ( import (
"errors" "errors"

View File

@@ -1,4 +1,4 @@
package imagefetcher package fetcher
import ( import (
"context" "context"

View File

@@ -1,6 +1,6 @@
// imagefetcher is responsible for downloading images using HTTP requests through various protocols // fetcher is responsible for downloading images using HTTP requests through various protocols
// defined in transport package // defined in transport package
package imagefetcher package fetcher
import ( import (
"context" "context"

View File

@@ -1,4 +1,4 @@
package imagefetcher package fetcher
import ( import (
"compress/gzip" "compress/gzip"

View File

@@ -5,9 +5,9 @@ import (
"errors" "errors"
"net/http" "net/http"
"github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/headerwriter" "github.com/imgproxy/imgproxy/v3/headerwriter"
"github.com/imgproxy/imgproxy/v3/ierrors" "github.com/imgproxy/imgproxy/v3/ierrors"
"github.com/imgproxy/imgproxy/v3/imagefetcher"
"github.com/imgproxy/imgproxy/v3/imagetype" "github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/imgproxy/imgproxy/v3/monitoring" "github.com/imgproxy/imgproxy/v3/monitoring"
"github.com/imgproxy/imgproxy/v3/monitoring/stats" "github.com/imgproxy/imgproxy/v3/monitoring/stats"
@@ -81,7 +81,7 @@ func (r *request) execute(ctx context.Context) error {
} }
// Respond with NotModified if image was not modified // Respond with NotModified if image was not modified
var nmErr imagefetcher.NotModifiedError var nmErr fetcher.NotModifiedError
if errors.As(err, &nmErr) { if errors.As(err, &nmErr) {
r.hwr.SetOriginHeaders(nmErr.Headers()) r.hwr.SetOriginHeaders(nmErr.Headers())

View File

@@ -7,10 +7,10 @@ import (
"sync" "sync"
"github.com/imgproxy/imgproxy/v3/cookies" "github.com/imgproxy/imgproxy/v3/cookies"
"github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/headerwriter" "github.com/imgproxy/imgproxy/v3/headerwriter"
"github.com/imgproxy/imgproxy/v3/httpheaders" "github.com/imgproxy/imgproxy/v3/httpheaders"
"github.com/imgproxy/imgproxy/v3/ierrors" "github.com/imgproxy/imgproxy/v3/ierrors"
"github.com/imgproxy/imgproxy/v3/imagefetcher"
"github.com/imgproxy/imgproxy/v3/monitoring" "github.com/imgproxy/imgproxy/v3/monitoring"
"github.com/imgproxy/imgproxy/v3/monitoring/stats" "github.com/imgproxy/imgproxy/v3/monitoring/stats"
"github.com/imgproxy/imgproxy/v3/options" "github.com/imgproxy/imgproxy/v3/options"
@@ -35,9 +35,9 @@ var (
// Handler handles image passthrough requests, allowing images to be streamed directly // Handler handles image passthrough requests, allowing images to be streamed directly
type Handler struct { type Handler struct {
config *Config // Configuration for the streamer config *Config // Configuration for the streamer
fetcher *imagefetcher.Fetcher // Fetcher instance to handle image fetching fetcher *fetcher.Fetcher // Fetcher instance to handle image fetching
hw *headerwriter.Writer // Configured HeaderWriter instance hw *headerwriter.Writer // Configured HeaderWriter instance
} }
// request holds the parameters and state for a single streaming request // request holds the parameters and state for a single streaming request
@@ -52,7 +52,7 @@ type request struct {
} }
// New creates new handler object // New creates new handler object
func New(config *Config, hw *headerwriter.Writer, fetcher *imagefetcher.Fetcher) (*Handler, error) { func New(config *Config, hw *headerwriter.Writer, fetcher *fetcher.Fetcher) (*Handler, error) {
if err := config.Validate(); err != nil { if err := config.Validate(); err != nil {
return nil, err return nil, err
} }

View File

@@ -16,9 +16,9 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/imgproxy/imgproxy/v3/config" "github.com/imgproxy/imgproxy/v3/config"
"github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/headerwriter" "github.com/imgproxy/imgproxy/v3/headerwriter"
"github.com/imgproxy/imgproxy/v3/httpheaders" "github.com/imgproxy/imgproxy/v3/httpheaders"
"github.com/imgproxy/imgproxy/v3/imagefetcher"
"github.com/imgproxy/imgproxy/v3/options" "github.com/imgproxy/imgproxy/v3/options"
"github.com/imgproxy/imgproxy/v3/transport" "github.com/imgproxy/imgproxy/v3/transport"
) )
@@ -55,9 +55,9 @@ func (s *HandlerTestSuite) SetupTest() {
tr, err := transport.New(trc) tr, err := transport.New(trc)
s.Require().NoError(err) s.Require().NoError(err)
fc := imagefetcher.NewDefaultConfig() fc := fetcher.NewDefaultConfig()
fetcher, err := imagefetcher.NewFetcher(tr, fc) fetcher, err := fetcher.NewFetcher(tr, fc)
s.Require().NoError(err) s.Require().NoError(err)
cfg := NewDefaultConfig() cfg := NewDefaultConfig()
@@ -356,9 +356,9 @@ func (s *HandlerTestSuite) TestHandlerCacheControl() {
tr, err := transport.New(trc) tr, err := transport.New(trc)
s.Require().NoError(err) s.Require().NoError(err)
fc := imagefetcher.NewDefaultConfig() fc := fetcher.NewDefaultConfig()
fetcher, err := imagefetcher.NewFetcher(tr, fc) fetcher, err := fetcher.NewFetcher(tr, fc)
s.Require().NoError(err) s.Require().NoError(err)
cfg := NewDefaultConfig() cfg := NewDefaultConfig()
@@ -453,8 +453,8 @@ func (s *HandlerTestSuite) TestHandlerCookiePassthrough() {
tr, err := transport.New(trc) tr, err := transport.New(trc)
s.Require().NoError(err) s.Require().NoError(err)
fc := imagefetcher.NewDefaultConfig() fc := fetcher.NewDefaultConfig()
fetcher, err := imagefetcher.NewFetcher(tr, fc) fetcher, err := fetcher.NewFetcher(tr, fc)
s.Require().NoError(err) s.Require().NoError(err)
cfg := NewDefaultConfig() cfg := NewDefaultConfig()
@@ -513,8 +513,8 @@ func (s *HandlerTestSuite) TestHandlerCanonicalHeader() {
tr, err := transport.New(trc) tr, err := transport.New(trc)
s.Require().NoError(err) s.Require().NoError(err)
fc := imagefetcher.NewDefaultConfig() fc := fetcher.NewDefaultConfig()
fetcher, err := imagefetcher.NewFetcher(tr, fc) fetcher, err := fetcher.NewFetcher(tr, fc)
s.Require().NoError(err) s.Require().NoError(err)
cfg := NewDefaultConfig() cfg := NewDefaultConfig()

View File

@@ -5,13 +5,13 @@ import (
"net/http" "net/http"
"github.com/imgproxy/imgproxy/v3/config" "github.com/imgproxy/imgproxy/v3/config"
"github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/ierrors" "github.com/imgproxy/imgproxy/v3/ierrors"
"github.com/imgproxy/imgproxy/v3/imagefetcher"
"github.com/imgproxy/imgproxy/v3/transport" "github.com/imgproxy/imgproxy/v3/transport"
) )
var ( var (
Fetcher *imagefetcher.Fetcher Fetcher *fetcher.Fetcher
// For tests. This needs to move to fetcher once we will have a way to isolate // For tests. This needs to move to fetcher once we will have a way to isolate
// the fetcher in tests. // the fetcher in tests.
@@ -45,12 +45,12 @@ func initDownloading() error {
return err return err
} }
c, err := imagefetcher.LoadFromEnv(imagefetcher.NewDefaultConfig()) c, err := fetcher.LoadFromEnv(fetcher.NewDefaultConfig())
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithPrefix("configuration error")) return ierrors.Wrap(err, 0, ierrors.WithPrefix("configuration error"))
} }
Fetcher, err = imagefetcher.NewFetcher(ts, c) Fetcher, err = fetcher.NewFetcher(ts, c)
if err != nil { if err != nil {
return ierrors.Wrap(err, 0, ierrors.WithPrefix("can't create image fetcher")) return ierrors.Wrap(err, 0, ierrors.WithPrefix("can't create image fetcher"))
} }

View File

@@ -3,13 +3,13 @@ package imagedata
import ( import (
"fmt" "fmt"
"github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/ierrors" "github.com/imgproxy/imgproxy/v3/ierrors"
"github.com/imgproxy/imgproxy/v3/imagefetcher"
) )
func wrapDownloadError(err error, desc string) error { func wrapDownloadError(err error, desc string) error {
return ierrors.Wrap( return ierrors.Wrap(
imagefetcher.WrapError(err), 0, fetcher.WrapError(err), 0,
ierrors.WithPrefix(fmt.Sprintf("can't download %s", desc)), ierrors.WithPrefix(fmt.Sprintf("can't download %s", desc)),
) )
} }

View File

@@ -9,7 +9,7 @@ import (
"os" "os"
"github.com/imgproxy/imgproxy/v3/asyncbuffer" "github.com/imgproxy/imgproxy/v3/asyncbuffer"
"github.com/imgproxy/imgproxy/v3/imagefetcher" "github.com/imgproxy/imgproxy/v3/fetcher"
"github.com/imgproxy/imgproxy/v3/imagetype" "github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/imgproxy/imgproxy/v3/security" "github.com/imgproxy/imgproxy/v3/security"
) )
@@ -63,7 +63,7 @@ func NewFromBase64(encoded string) (ImageData, error) {
} }
// sendRequest is a common logic between sync and async download. // sendRequest is a common logic between sync and async download.
func sendRequest(ctx context.Context, url string, opts DownloadOptions) (*imagefetcher.Request, *http.Response, http.Header, error) { func sendRequest(ctx context.Context, url string, opts DownloadOptions) (*fetcher.Request, *http.Response, http.Header, error) {
h := make(http.Header) h := make(http.Header)
// NOTE: This will be removed in the future when our test context gets better isolation // NOTE: This will be removed in the future when our test context gets better isolation