Do not add base URL if the image URL already contains it

This commit is contained in:
DarthSim
2021-09-07 17:39:24 +06:00
parent 8f062a43ee
commit e0f9fab772
2 changed files with 11 additions and 7 deletions
+1 -1
View File
@@ -334,7 +334,7 @@ imgproxy can send logs to syslog, but this feature is disabled by default. To en
## Miscellaneous
* `IMGPROXY_BASE_URL`: base URL prefix that will be added to every requested image URL. For example, if the base URL is `http://example.com/images` and `/path/to/image.png` is requested, imgproxy will download the source image from `http://example.com/images/path/to/image.png`. Default: blank.
* `IMGPROXY_BASE_URL`: base URL prefix that will be added to every requested image URL. For example, if the base URL is `http://example.com/images` and `/path/to/image.png` is requested, imgproxy will download the source image from `http://example.com/images/path/to/image.png`. If the image URL already contains the prefix, it won't be added. Default: blank.
* `IMGPROXY_USE_LINEAR_COLORSPACE`: when `true`, imgproxy will process images in linear colorspace. This will slow down processing. Note that images won't be fully processed in linear colorspace while shrink-on-load is enabled (see below).
* `IMGPROXY_DISABLE_SHRINK_ON_LOAD`: when `true`, disables shrink-on-load for JPEG and WebP. Allows to process the whole image in linear colorspace but dramatically slows down resizing and increases memory usage when working with large images.
* `IMGPROXY_STRIP_METADATA`: when `true`, imgproxy will strip all metadata (EXIF, IPTC, etc.) from JPEG and WebP output images. Default: `true`.
+10 -6
View File
@@ -304,6 +304,14 @@ func colorFromHex(hexcolor string) (rgbColor, error) {
return c, nil
}
func addBaseURL(u string) string {
if len(conf.BaseURL) == 0 || strings.HasPrefix(u, conf.BaseURL) {
return u
}
return fmt.Sprintf("%s%s", conf.BaseURL, u)
}
func decodeBase64URL(parts []string) (string, string, error) {
var format string
@@ -327,9 +335,7 @@ func decodeBase64URL(parts []string) (string, string, error) {
return "", "", fmt.Errorf("Invalid url encoding: %s", encoded)
}
fullURL := fmt.Sprintf("%s%s", conf.BaseURL, string(imageURL))
return fullURL, format, nil
return addBaseURL(string(imageURL)), format, nil
}
func decodePlainURL(parts []string) (string, string, error) {
@@ -355,9 +361,7 @@ func decodePlainURL(parts []string) (string, string, error) {
return "", "", fmt.Errorf("Invalid url encoding: %s", encoded)
}
fullURL := fmt.Sprintf("%s%s", conf.BaseURL, unescaped)
return fullURL, format, nil
return addBaseURL(unescaped), format, nil
}
func decodeURL(parts []string) (string, string, error) {