2

I want to implement a shadowban. Above a certain rate limit, I want to not respond anything to a request.

I couldn't find how to do that in the doc.

It seems setting body = null will still trigger a response.

How may I prevent koa@2 from answering to a request?

Offirmo
  • 18,962
  • 12
  • 76
  • 97

1 Answers1

2

You should be able to do this by setting ctx.respond = false in your route handler.

Having a look through koa's source code shows this: https://github.com/koajs/koa/blob/master/lib/application.js#L201

function respond(ctx) {
  // allow bypassing koa
  if (false === ctx.respond) return;
  // ...