1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-03 23:19:17 +02:00

Adds an option to allows only presets in the URL. (#156)

* Adds an option to allows only presets in the URL.  If it's enabled, only presets can be used, and all other URL formats are disabled. You can allow it to with an env var.

If it's enabled, only presets can be used, and all other URL formats are disabled. You can allow it to with an env var.

* Add parsePathPresets function

Following DarthSim suggestion, I added a parsePathPresets function and remove the code inside parseURLOptions.
This commit is contained in:
Carlos Brando
2019-05-16 07:24:42 -03:00
committed by Sergey Alexandrovich
parent c6145a8e69
commit e071396fd6
5 changed files with 83 additions and 2 deletions

View File

@@ -803,6 +803,33 @@ func parsePathAdvanced(parts []string, headers *processingHeaders) (string, *pro
return url, po, nil
}
func parsePathPresets(parts []string, headers *processingHeaders) (string, *processingOptions, error) {
po, err := defaultProcessingOptions(headers)
if err != nil {
return "", po, err
}
presets := strings.Split(parts[0], ":")
urlParts := parts[1:]
if err := applyPresetOption(po, presets); err != nil {
return "", nil, err
}
url, extension, err := decodeURL(urlParts)
if err != nil {
return "", po, err
}
if len(extension) > 0 {
if err := applyFormatOption(po, []string{extension}); err != nil {
return "", po, err
}
}
return url, po, nil
}
func parsePathBasic(parts []string, headers *processingHeaders) (string, *processingOptions, error) {
var err error
@@ -875,7 +902,9 @@ func parsePath(ctx context.Context, r *http.Request) (context.Context, error) {
var po *processingOptions
var err error
if _, ok := resizeTypes[parts[1]]; ok {
if conf.OnlyPresets {
imageURL, po, err = parsePathPresets(parts[1:], headers)
} else if _, ok := resizeTypes[parts[1]]; ok {
imageURL, po, err = parsePathBasic(parts[1:], headers)
} else {
imageURL, po, err = parsePathAdvanced(parts[1:], headers)