koajs / ratelimit

Rate limiter middleware
MIT License
485 stars 57 forks source link

Custom header names #19

Closed ruiquelhas closed 8 years ago

ruiquelhas commented 8 years ago

Hi. As far as I can tell, there is currently no support for setting custom header names (for X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset). Would you consider accepting a PR for it?

Thanks.

haoxins commented 8 years ago

Actually, you can catch rate-limit errors, and do anything you want.

ruiquelhas commented 8 years ago

Yes, but it feels a bit hacky, don't you think? I would like to override the headers for any kind of response (be it an error or not), and calling throw() with a 200 OK seems weird.

haoxins commented 8 years ago

Should we add a hook function such as onReachLimit(ctx, limit) ?

cc @tj @jonathanong @koajs/ratelimit

dead-horse commented 8 years ago

onReachLimit can't resolve @ruiquelhas 's problem, these headers will always set.

dead-horse commented 8 years ago

https://github.com/koajs/ratelimit/blob/master/index.js#L55

ruiquelhas commented 8 years ago

I don't think a hook would be the best solution for my problem. Providing the header names in the options and just use them instead will probably make more sense.

I have a branch with those changes, I just wanted to know if it made sense to you before submiting the PR.

haoxins commented 8 years ago

I have a branch with those changes, I just wanted to know if it made sense to you before submiting the PR.

@ruiquelhas can you submit PR first :)

haoxins commented 8 years ago

@dead-horse Oh, yea! My fault.