For Workes & Pages, what is the name of the domain?
100wolf.ops59.workers.dev
What is the issue or error you’re encountering
worker is not being run. Cloudflare throws 400 and nothing in logs
What are the steps to reproduce the issue?
I have a SOLR search bar on my site. When I search for “100% wolf” it generates a url that looks like this:
https://www.example.org/search/100%%20wolf
This then causes cloudflare to throw a 400 Bad Request because even though the space was properly converted to %20, the % was not converted to %25.
I have tried to use a worker to match and replace the bare % with %25:
/**
- Uses regex to fix URL encoding when someone searches for “100% wolf”
*/
addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request));
})
async function handleRequest(request) {
let url = new URL(request.url);
// Replace any bare ‘%’ with ‘%25’
url.pathname = url.pathname.replace(/(?<!%)%(?![0-9A-Fa-f]{2})/g, ‘%25’);
// Forward the modified request to the origin server
return fetch(url, request);
}
When I have the route as example.org/search/* and I have logs running, I get a worker log when I search for “test” (or anything else without a ‘%’) but I don’t get anything in the logs when I search for “100% wolf”.
Even though I am pretty sure the code and regex are correct, it doesn’t matter because cloudflare throws an error before the code is run.
Not sure where to go from here. Any ideas?