Viktor Sokolov 3 месяцев назад
Родитель
Сommit
e6dc05f06e
2 измененных файлов с 25 добавлено и 24 удалено
  1. 24 24
      handlers/processing/handler.go
  2. 1 0
      handlers/processing/request.go

+ 24 - 24
handlers/processing/handler.go

@@ -14,7 +14,6 @@ import (
 	"github.com/imgproxy/imgproxy/v3/ierrors"
 	"github.com/imgproxy/imgproxy/v3/imagedata"
 	"github.com/imgproxy/imgproxy/v3/monitoring"
-	"github.com/imgproxy/imgproxy/v3/options"
 	"github.com/imgproxy/imgproxy/v3/options/keys"
 	optionsparser "github.com/imgproxy/imgproxy/v3/options/parser"
 	"github.com/imgproxy/imgproxy/v3/processing"
@@ -75,54 +74,46 @@ func (h *Handler) Execute(
 	ctx := req.Context()
 
 	// Verify URL signature and extract image url and processing options
-	imageURL, o, features, mm, err := h.newRequest(ctx, req)
+	r, err := h.newRequest(ctx, req)
 	if err != nil {
 		return err
 	}
 
 	// if processing options indicate raw image streaming, stream it and return
-	if o.GetBool(keys.Raw, false) {
-		return h.stream.Execute(ctx, req, imageURL, reqID, o, rw)
+	if r.opts.GetBool(keys.Raw, false) {
+		return h.stream.Execute(ctx, req, r.imageURL, reqID, r.opts, rw)
 	}
 
-	hReq := &request{
-		HandlerContext: h,
-
-		reqID:          reqID,
-		req:            req,
-		rw:             rw,
-		config:         h.config,
-		opts:           o,
-		secops:         h.Security().NewOptions(o),
-		imageURL:       imageURL,
-		monitoringMeta: mm,
-		features:       features,
-	}
+	r.reqID = reqID
+	r.req = req
+	r.rw = rw
+	r.config = h.config
+	r.secops = h.Security().NewOptions(r.opts)
 
-	return hReq.execute(ctx)
+	return r.execute(ctx)
 }
 
 // newRequest extracts image url and processing options from request URL and verifies them
 func (h *Handler) newRequest(
 	ctx context.Context,
 	req *http.Request,
-) (string, *options.Options, *clientfeatures.Features, monitoring.Meta, error) {
+) (*request, error) {
 	// let's extract signature and valid request path from a request
 	path, signature, err := handlers.SplitPathSignature(req)
 	if err != nil {
-		return "", nil, nil, nil, err
+		return nil, err
 	}
 
 	// verify the signature (if any)
 	if err = h.Security().VerifySignature(signature, path); err != nil {
-		return "", nil, nil, nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategorySecurity))
+		return nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategorySecurity))
 	}
 
 	// parse image url and processing options
 	features := h.ClientFeaturesDetector().Features(req.Header)
 	o, imageURL, err := h.OptionsParser().ParsePath(path, &features)
 	if err != nil {
-		return "", nil, nil, nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryPathParsing))
+		return nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategoryPathParsing))
 	}
 
 	// get image origin and create monitoring meta object
@@ -144,10 +135,19 @@ func (h *Handler) newRequest(
 	// verify that image URL came from the valid source
 	err = h.Security().VerifySourceURL(imageURL)
 	if err != nil {
-		return "", options.New(), nil, mm, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategorySecurity))
+		return nil, ierrors.Wrap(err, 0, ierrors.WithCategory(handlers.CategorySecurity))
 	}
 
-	return imageURL, o, &features, mm, nil
+	return &request{
+		HandlerContext: h,
+
+		imageURL:       imageURL,
+		path:           path,
+		opts:           o,
+		features:       &features,
+		monitoringMeta: mm,
+		req:            req,
+	}, nil
 }
 
 // imageOrigin extracts image origin from URL

+ 1 - 0
handlers/processing/request.go

@@ -29,6 +29,7 @@ type request struct {
 	opts           *options.Options
 	secops         security.Options
 	imageURL       string
+	path           string
 	monitoringMeta monitoring.Meta
 	features       *clientfeatures.Features
 }