{"id":20510652,"url":"https://github.com/twilight-rs/http-proxy","last_synced_at":"2025-04-06T16:10:16.158Z","repository":{"id":37185213,"uuid":"210310182","full_name":"twilight-rs/http-proxy","owner":"twilight-rs","description":"Ratelimited Discord HTTP API proxy.","archived":false,"fork":false,"pushed_at":"2025-03-10T06:51:36.000Z","size":194,"stargazers_count":105,"open_issues_count":6,"forks_count":32,"subscribers_count":8,"default_branch":"trunk","last_synced_at":"2025-03-30T15:07:19.249Z","etag":null,"topics":["discord","discord-api","discord-bot","http-proxy","ratelimiter","rust","twilight-rs"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twilight-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2019-09-23T09:03:05.000Z","updated_at":"2025-03-10T06:51:39.000Z","dependencies_parsed_at":"2024-02-09T15:02:48.484Z","dependency_job_id":"1a9222e8-74a8-418e-a883-358a6e5417e2","html_url":"https://github.com/twilight-rs/http-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/twilight-rs%2Fhttp-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Fhttp-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Fhttp-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Fhttp-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twilight-rs","download_url":"https://codeload.github.com/twilight-rs/http-proxy/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509221,"owners_count":20950232,"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":["discord","discord-api","discord-bot","http-proxy","ratelimiter","rust","twilight-rs"],"created_at":"2024-11-15T20:30:15.986Z","updated_at":"2025-04-06T16:10:16.135Z","avatar_url":"https://github.com/twilight-rs.png","language":"Rust","funding_links":[],"categories":["MISC"],"sub_categories":["Rust"],"readme":"# twilight-http-proxy\n\n`http-proxy` is a ratelimited HTTP proxy in front of the Discord API, making use\nof [twilight].\n\n## Use\n\nThis proxy is not a \"real\" HTTP `CONNECT` TCP proxy, it instead mocks the\nDiscord API.\n\nUsing it is as easy as changing the base of all routes from `discord.com` to\n`localhost:3000`, like so:\n\n```bash\n# Previously\n$ curl https://discord.com/api/users/@me\n# With the proxy\n$ curl http://localhost:3000/api/users/@me\n\n# Or other API versions\n$ curl http://localhost:3000/users/@me\n$ curl http://localhost:3000/api/users/@me\n$ curl http://localhost:3000/api/v8/users/@me\n```\n\nThe proxy actively supports routes from API v10, but will also try to request\nthe corresponding routes on older or newer API versions if you so request in\nthe URL.\n\n`twilight_http` natively supports using `twilight_http_proxy`, so you can use\nit like this:\n\n```rust\nuse twilight_http::Client;\nuse std::error::Error;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn Error + Send + Sync\u003e\u003e {\n    let client = Client::builder()\n        .proxy(\"localhost:3000\", true)\n        .ratelimiter(None)\n        .build();\n\n    Ok(())\n}\n```\n\nThis will use the running proxy, skip the ratelimiter (since the proxy does\nratelimiting itself), and will request over HTTP.\n\nIf you are using a different Discord API client, make sure that you are not\nratelimiting outgoing requests, because the proxy will do this instead. Very\nshort HTTP client timeouts may also cause issues with longer ratelimits.\n\n### Multiple applications\n\nBy default, the proxy will use the token provided in the `DISCORD_TOKEN`\nenviroment variable for all requests. You can bypass this by providing a\ndifferent token in the `Authorization` header yourself.\n\nThe proxy will keep track of ratelimits on a per-token basis, so using multiple\napplications is as easy as sending the header alongside your requests.\n\nYou can configure how long the proxy stores ratelimit information with these\nenviroment variables:\n\n- `CLIENT_DECAY_TIMEOUT` (in seconds; defaults to 1 hour) sets the timeout\n  after which ratelimiting information will be dropped due to not being used\n  anymore\n- `CLIENT_CACHE_MAX_SIZE` (defaults to no limit) limits the amount of\n  ratelimiting information in the cache - if full, the least recently used\n  ratelimiting information will be removed\n- `METRIC_TIMEOUT` (in seconds; defaults to 5 minutes) controls how long\n  metrics (metrics are identified by their combination of http method + route +\n  response code + ratelimit scope) will continue to be reported past their last\n  occurence before they are discarded. This avoids polluting your metrics with\n  one off request metrics (9 datapoints per scrape) for long after it happened\n\n### Running via Docker\n\n| :exclamation:  The published images on Docker Hub will not work from April 14, 2023 due to Docker removing free team organizations! Use the new location described below. |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\nPrebuilt Docker images are published on [Github's container registry].\n\n```sh\n$ docker run -itd -e DISCORD_TOKEN=\"my token\" -p 3000:80 ghcr.io/twilight-rs/http-proxy\n# Or with metrics enabled\n$ docker run -itd -e DISCORD_TOKEN=\"my token\" -p 3000:80 ghcr.io/twilight-rs/http-proxy:metrics\n```\n\nThis will set the discord token to `\"my token\"` and map the bound port to port\n3000 on the host machine.\n\nImages come in two variants: The `metrics` tag is a build with prometheus metrics\nsupport, the `latest` tag is a build without metrics support. Both support `x86_64`\nas well as `aarch64` architectures.\n\n### Running via Cargo\n\nBuild the binary:\n\n```sh\n$ cargo build --release\n$ DISCORD_TOKEN=\"my token\" PORT=3000 ./target/release/twilight-http-proxy\n```\n\nThis will set the discord token to `\"my token\"` and bind to port 3000.\n\n### Additional configuration\n\nHTTP2 may cause issues with high concurrency (i.e. many concurrent requests).\nIf you encounter frequent error logs related to this, force the use of HTTP1 by\nsetting `DISABLE_HTTP2` to any value when running the proxy.\n\n## Prometheus metrics\n\nThe HTTP proxy can expose prometheus metrics when compiled with the\n`expose-metrics` feature. These metrics are then available on the `/metrics`\nendpoint.\nYou can set the metrics key used for the histogram data by setting the\n`METRIC_KEY` environment variable.\n\nThe exported histogram includes timing percentiles, response status codes,\nrequest path and request method. Calls to the metrics endpoint itself are not\nincluded in the metrics.\n\n## Error behaviour\n\nIf processing an incoming request fails, the proxy will respond with a 5xx\nstatus code and a helpful error message in the response body. Currently, these\nstatus codes include:\n\n- `500` if the proxy generates an invalid URI or the ratelimiter fails\n  internally\n- `501` if the client requested an unsupported API path or used an unsupported\n  HTTP method\n- `502` if the request made by the proxy fails\n\n[twilight]: https://github.com/twilight-rs/twilight\n[github's container registry]: https://github.com/twilight-rs/http-proxy/pkgs/container/http-proxy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilight-rs%2Fhttp-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilight-rs%2Fhttp-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilight-rs%2Fhttp-proxy/lists"}