Key error when adding a querystring to the regex on REWRITE_MATCH_PATTERN and REWRITE_SUBSTITUTION #526
-
I am looking to migrate from thumbor to this solution. I tried using the REWRITE_MATCH_PATTERN and REWRITE_SUBSTITUTION and it seems to work fine till I add a "?download_filename=" string to the match. When adding this string to REWRITE_MATCH_PATTERN I get a 404. The app makes calls using this format:
And this solution works with this format:
Regex being used:
After that if I make a request to let's say: https://cloudfronturi/213412332/0x480/filters:format(jpeg)?download_filename=cat.jpg I get the error: "The image 213412332/ does not exist or the request may not be base64 encoded properly." Looking at the code I checked the function that makes the match: parseCustomPath(path) {
const { REWRITE_MATCH_PATTERN, REWRITE_SUBSTITUTION } = process.env;
if (path === void 0) {
throw new Error("ThumborMapping::ParseCustomPath::PathUndefined");
} else if (REWRITE_MATCH_PATTERN === void 0) {
throw new Error("ThumborMapping::ParseCustomPath::RewriteMatchPatternUndefined");
} else if (REWRITE_SUBSTITUTION === void 0) {
throw new Error("ThumborMapping::ParseCustomPath::RewriteSubstitutionUndefined");
} else {
let parsedPath = "";
if (typeof REWRITE_MATCH_PATTERN === "string") {
const patternStrings = REWRITE_MATCH_PATTERN.split("/");
const flags = patternStrings.pop();
const parsedPatternString = REWRITE_MATCH_PATTERN.slice(1, REWRITE_MATCH_PATTERN.length - 1 - flags.length);
const regExp = new RegExp(parsedPatternString, flags);
parsedPath = path.replace(regExp, REWRITE_SUBSTITUTION);
} else {
parsedPath = path.replace(REWRITE_MATCH_PATTERN, REWRITE_SUBSTITUTION);
}
return parsedPath;
}
} After executing this piece of code passing the env variables specified above, I get the correct parsing. My question is: Is the use of querystring not suported when using the regex substitution? Or am I just doing something wrong? I would apreciate any kind of help, thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@YasenMakioui We will take a look and get back to you on this |
Beta Was this translation helpful? Give feedback.
-
@YasenMakioui The order of processing may be what is preventing this configuration from working. The signature validation is done before the rewrite processing so the rewrite cannot be used to parse out the signature. |
Beta Was this translation helpful? Give feedback.
@YasenMakioui The order of processing may be what is preventing this configuration from working. The signature validation is done before the rewrite processing so the rewrite cannot be used to parse out the signature.
The code would have to be customized for this specific use case.