mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 12:12:40 +02:00
feat: Implement AlwaysRasterizeSvg (#1257)
Implement AlwaysRasterizeSvg Add sanitize to skip processing Add tests Refactoring skipProcessing
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -372,32 +373,28 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
checkErr(ctx, "timeout", router.CheckTimeout(ctx))
|
||||
|
||||
if originData.Type == po.Format || po.Format == imagetype.Unknown {
|
||||
// Don't process SVG
|
||||
if originData.Type == imagetype.SVG {
|
||||
if config.SanitizeSvg {
|
||||
sanitized, svgErr := svg.Sanitize(originData)
|
||||
checkErr(ctx, "svg_processing", svgErr)
|
||||
// Skip processing svg with unknown or the same destination imageType
|
||||
// if it's not forced by AlwaysRasterizeSvg option
|
||||
// Also skip processing if the format is in SkipProcessingFormats
|
||||
shouldSkipProcessing := (originData.Type == po.Format || po.Format == imagetype.Unknown) &&
|
||||
(slices.Contains(po.SkipProcessingFormats, originData.Type) ||
|
||||
originData.Type == imagetype.SVG && !config.AlwaysRasterizeSvg)
|
||||
|
||||
// Since we'll replace origin data, it's better to close it to return
|
||||
// it's buffer to the pool
|
||||
originData.Close()
|
||||
if shouldSkipProcessing {
|
||||
if originData.Type == imagetype.SVG && config.SanitizeSvg {
|
||||
sanitized, svgErr := svg.Sanitize(originData)
|
||||
checkErr(ctx, "svg_processing", svgErr)
|
||||
|
||||
originData = sanitized
|
||||
}
|
||||
// Since we'll replace origin data, it's better to close it to return
|
||||
// it's buffer to the pool
|
||||
originData.Close()
|
||||
|
||||
originData = sanitized
|
||||
|
||||
respondWithImage(reqID, r, rw, statusCode, originData, po, imageURL, originData)
|
||||
return
|
||||
}
|
||||
|
||||
if len(po.SkipProcessingFormats) > 0 {
|
||||
for _, f := range po.SkipProcessingFormats {
|
||||
if f == originData.Type {
|
||||
respondWithImage(reqID, r, rw, statusCode, originData, po, imageURL, originData)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
respondWithImage(reqID, r, rw, statusCode, originData, po, imageURL, originData)
|
||||
return
|
||||
}
|
||||
|
||||
if !vips.SupportsLoad(originData.Type) {
|
||||
|
Reference in New Issue
Block a user