{"id":15657338,"url":"https://github.com/joshdevins/node-rate-limiter-proxy","last_synced_at":"2025-05-05T04:13:50.602Z","repository":{"id":1193065,"uuid":"1097889","full_name":"joshdevins/node-rate-limiter-proxy","owner":"joshdevins","description":"A very simple node.js HTTP proxy providing usage rate limiting using Redis","archived":false,"fork":false,"pushed_at":"2023-10-06T08:20:30.000Z","size":46,"stargazers_count":23,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-05T04:13:43.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshdevins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-11-20T17:52:12.000Z","updated_at":"2023-10-06T08:20:34.000Z","dependencies_parsed_at":"2024-10-23T05:09:22.443Z","dependency_job_id":"88cd770d-0e1c-414c-afc2-719a4b735612","html_url":"https://github.com/joshdevins/node-rate-limiter-proxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdevins%2Fnode-rate-limiter-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdevins%2Fnode-rate-limiter-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdevins%2Fnode-rate-limiter-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdevins%2Fnode-rate-limiter-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshdevins","download_url":"https://codeload.github.com/joshdevins/node-rate-limiter-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252436586,"owners_count":21747472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T13:06:23.151Z","updated_at":"2025-05-05T04:13:50.567Z","avatar_url":"https://github.com/joshdevins.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"HTTP Rate Limiting Proxy Server\n===\n\nA very simple node.js HTTP proxy providing usage rate limiting using Redis. This implementation has been tested against node.js v0.2.5 and Redis v2.0.4.\n\nBasic Usage\n---\n\n\tnode node-rate-limiter-proxy.js\n\t\nIf you use something like \u003ccode\u003ecurl\u003c/code\u003e to make requests to the proxy, you will see some extra headers that help you understand the current state of the limiter in Redis. The custom headers used are very similar to those in the [Twitter API](http://dev.twitter.com/pages/rate_limiting_faq#checking).\n\n\t$ curl -v --header \"Host: localhost:80\" http://josh:devins@localhost:8080/\n\n\t\u003e GET / HTTP/1.1\n\t\u003e Authorization: Basic am9zaDpkZXZpbnM=\n\t\u003e User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3\n\t\u003e Accept: */*\n\t\u003e Host: localhost\n\t\u003e \n\t\u003c HTTP/1.1 200 OK\n\t\u003c date: Sat, 20 Nov 2010 23:35:27 GMT\n\t\u003c server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8l DAV/2\n\t...\n\t\u003c X-RateLimit-MaxRequests: 10\n\t\u003c X-RateLimit-Requests: 1\n\t\u003c X-RateLimit-Remaining: 9\n\t\u003c X-RateLimit-TTL: 60\n\t\u003c X-RateLimit-Reset: 1290342852\n\nYou will also need to either set your client to use a proxy or explicitly set the \u003ccode\u003eHost\u003c/code\u003e header when testing since this is what the proxy uses to determine the destination for the proxied request. This is particularly important when both proxy and upstream server are running on \u003ccode\u003elocalhost\u003c/code\u003e otherwise you will get into an endless loop.\n\nConfiguration\n---\n\nAll configuration is in \u003ccode\u003econfig.js\u003c/code\u003e. This includes a function to determine how to build the access key. An access key is what is used to uniquely identify a user or set of users whose access rates you want to control. By default, the key is built from the \u003ccode\u003eAuthentication\u003c/code\u003e header, however it could just as easily be built up from the source IP address or request path.\n\nAPI Usage\n---\n\nIncluded is a very basic API allowing a client to fetch the current state of the rate limiter for either: an arbitrary key or an exact URL/request.\n\nTo retrieve an arbitrary key, the key might first need to be URL encoded. There needs to be some insight into the white box that is the proxy since the client needs to be aware of how the key is built. Since the default is to use the Authentication header as the key, I already have a URL encoded value (see the request headers in the first example of basic usage). The \u003ccode\u003estatus\u003c/code\u003e URI path is configurable as well in case that collides with a URI on the backing/proxied server.\n\n    $ curl http://localhost:8080/status/am9zaDpkZXZpbnM=\n\t{\"max_requests\":10,\"requests\":3,\"remaining\":7,\"ttl\":16,\"reset\":1290347995}\n\nTo test the status of the rate limiter for a specific request, just add the header \u003ccode\u003eX-RateLimit-Status\u003c/code\u003e to a regular request. This will *NOT* send a request to the backing server but instead just return the status object.\n\n\t$ curl --header 'X-RateLimit-Status: true' --header 'Host: localhost' http://josh:devins@localhost:8080/this/is/the/path\n\t{\"max_requests\":10,\"requests\":0,\"remaining\":10,\"ttl\":60,\"reset\":1290348148}\n\nAt the moment, only JSON responses are supported however this can easily be extended.\n\nTODO\n---\n\n * better Redis failure handling mid-request\n * HTTPS support\n * ensure race condition goes away between TTL expiry check and reset (upstream server can get stampeded)\n   * optimistic locking in Redis (requires Redis 2.1.0)\n\nAcknowledgements\n---\n\n * [node_redis](http://github.com/mranney/node_redis) (Redis library)\n * [nodejs-proxy](https://github.com/pkrumins/nodejs-proxy) (short and simple basis for the core proxy code, configuration example)\n * [HTTP client connection error handling](http://rentzsch.tumblr.com/post/664884799/node-js-handling-refused-http-client-connections)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdevins%2Fnode-rate-limiter-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdevins%2Fnode-rate-limiter-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdevins%2Fnode-rate-limiter-proxy/lists"}