mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-25 19:24:38 +02:00
Add IMGPROXY_ARGUMENTS_SEPARATOR and IMGPROXY_PRESETS_SEPARATOR configs
This commit is contained in:
@@ -1173,7 +1173,7 @@ func parsePathPresets(parts []string, headers http.Header) (*ProcessingOptions,
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
presets := strings.Split(parts[0], ":")
|
||||
presets := strings.Split(parts[0], config.ArgumentsSeparator)
|
||||
urlParts := parts[1:]
|
||||
|
||||
if err = applyPresetOption(po, presets); err != nil {
|
||||
|
@@ -138,6 +138,19 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
|
||||
s.Require().Equal(imagetype.PNG, po.Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseWithArgumentsSeparator() {
|
||||
config.ArgumentsSeparator = ","
|
||||
|
||||
path := "/size,100,100,1/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(100, po.Width)
|
||||
s.Require().Equal(100, po.Height)
|
||||
s.Require().True(po.Enlarge)
|
||||
}
|
||||
|
||||
// func (s *ProcessingOptionsTestSuite) TestParseURLAllowedSource() {
|
||||
// config.AllowedSources = []string{"local://", "http://images.dev/"}
|
||||
|
||||
@@ -546,25 +559,6 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
|
||||
s.Require().InDelta(1.0, po.Dpr, 0.0001)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
urlOption{Name: "blur", Args: []string{"0.2"}},
|
||||
}
|
||||
presets["test2"] = urlOptions{
|
||||
urlOption{Name: "quality", Args: []string{"50"}},
|
||||
}
|
||||
|
||||
path := "/test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
|
||||
path := "/skp:jpg:png/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
@@ -599,6 +593,25 @@ func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
|
||||
s.Require().Equal(errExpiredURL.Error(), err.Error())
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
urlOption{Name: "blur", Args: []string{"0.2"}},
|
||||
}
|
||||
presets["test2"] = urlOptions{
|
||||
urlOption{Name: "quality", Args: []string{"50"}},
|
||||
}
|
||||
|
||||
path := "/test1:test2/plain/http://images.dev/lorem/ipsum.jpg"
|
||||
|
||||
po, _, err := ParsePath(path, make(http.Header))
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().InDelta(float32(0.2), po.Blur, 0.0001)
|
||||
s.Require().Equal(50, po.Quality)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
|
||||
config.OnlyPresets = true
|
||||
presets["test1"] = urlOptions{
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package options
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
)
|
||||
|
||||
type urlOption struct {
|
||||
Name string
|
||||
@@ -14,7 +18,7 @@ func parseURLOptions(opts []string) (urlOptions, []string) {
|
||||
urlStart := len(opts) + 1
|
||||
|
||||
for i, opt := range opts {
|
||||
args := strings.Split(opt, ":")
|
||||
args := strings.Split(opt, config.ArgumentsSeparator)
|
||||
|
||||
if len(args) == 1 {
|
||||
urlStart = i
|
||||
|
Reference in New Issue
Block a user