1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-07 11:36:25 +02:00

Add IMGPROXY_BASE64_URL_INCLUDES_FILENAME config

This commit is contained in:
DarthSim 2025-01-16 20:50:04 +03:00
parent 09e305c053
commit 0f37d62fd8
4 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## [Unreleased]
### Added
- Add [IMGPROXY_BASE64_URL_INCLUDES_FILENAME](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_BASE64_URL_INCLUDES_FILENAME) config.
## [3.27.1] - 2025-01-13
### Added
- Add [IMGPROXY_SOURCE_URL_QUERY_SEPARATOR](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_SOURCE_URL_QUERY_SEPARATOR) config.

View File

@ -142,8 +142,9 @@ var (
LastModifiedEnabled bool
BaseURL string
URLReplacements []URLReplacement
BaseURL string
URLReplacements []URLReplacement
Base64URLIncludesFilename bool
Presets []string
OnlyPresets bool
@ -350,6 +351,7 @@ func Reset() {
BaseURL = ""
URLReplacements = make([]URLReplacement, 0)
Base64URLIncludesFilename = false
Presets = make([]string, 0)
OnlyPresets = false
@ -604,6 +606,7 @@ func Configure() error {
if err := configurators.Replacements(&URLReplacements, "IMGPROXY_URL_REPLACEMENTS"); err != nil {
return err
}
configurators.Bool(&Base64URLIncludesFilename, "IMGPROXY_BASE64_URL_INCLUDES_FILENAME")
presetsSep := ","
configurators.String(&presetsSep, "IMGPROXY_PRESETS_SEPARATOR")

View File

@ -32,6 +32,18 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
s.Require().Equal(imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithFilename() {
config.Base64URLIncludesFilename = true
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
path := fmt.Sprintf("/size:100:100/%s.png/puppy.jpg", base64.RawURLEncoding.EncodeToString([]byte(originURL)))
po, imageURL, err := ParsePath(path, make(http.Header))
s.Require().NoError(err)
s.Require().Equal(originURL, imageURL)
s.Require().Equal(imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
path := fmt.Sprintf("/size:100:100/%s", base64.RawURLEncoding.EncodeToString([]byte(originURL)))

View File

@ -27,6 +27,10 @@ func preprocessURL(u string) string {
func decodeBase64URL(parts []string) (string, string, error) {
var format string
if len(parts) > 1 && config.Base64URLIncludesFilename {
parts = parts[:len(parts)-1]
}
encoded := strings.Join(parts, "")
urlParts := strings.Split(encoded, ".")