Created
July 25, 2024 21:07
-
-
Save duggan/891093224dd7f10d00328f0f165a6719 to your computer and use it in GitHub Desktop.
Cloudflare Worker that very slowly responds to unexpected requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/index.js | |
var src_default = { | |
async fetch(request, env, ctx) { | |
const url = new URL(request.url); | |
if (url.pathname === "/") { | |
let res = await fetch(request); | |
return res; | |
} | |
if (url.pathname.startsWith("/example/")) { | |
let res = await fetch(request); | |
return res; | |
} | |
return new Response( | |
new ReadableStream({ | |
start(controller) { | |
const message = "Not Found"; | |
let position = 0; | |
const chunkSize = 1; | |
function push() { | |
if (position < message.length) { | |
controller.enqueue(new TextEncoder().encode(message.slice(position, position + chunkSize))); | |
position += chunkSize; | |
setTimeout(push, 1e4); | |
} else { | |
controller.close(); | |
} | |
} | |
push(); | |
} | |
}), | |
{ | |
// Set headers as needed | |
status: 404, | |
headers: { "Content-Type": "text/plain" } | |
} | |
); | |
} | |
}; | |
export { | |
src_default as default | |
}; | |
//# sourceMappingURL=index.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment