twilight-rs / http-proxy Goto Github PK
View Code? Open in Web Editor NEWRatelimited Discord HTTP API proxy.
License: ISC License
Ratelimited Discord HTTP API proxy.
License: ISC License
At the moment the proxy will break if presented with a new unknown path.
We should be able to handle it in some way.
Update twilight-http
to 0.5 in order to support slash commands (see issue #21).
checks fail with this error, failing the checks of every pr which makes us unable to see if the pr itself is correct, holding us back from merging prs
Slash commands support does not appear to exist in this proxy. I tried to add this myself, but I feel quite ill at the moment plus Request appears to have had some breaking changes to make it protected, so I ended up giving up for now.
Is it possible to use this server to send POST requests to discord webhooks?
I recently tried using the following URL http://localhost:3000/api/webhooks/my_webhook
, this is replacing https://discord.com/api/webhooks/my_webhook
with http://localhost:3000
as the base.
The post request failed, and this is the log from the server
2022-08-15T04:33:41.681536Z INFO twilight_http_proxy: Listening on http://0.0.0.0:3000
2022-08-15T04:33:51.290020Z ERROR twilight_http_proxy: Error when requesting the Discord API: hyper::Error(Connect, ConnectError("dns error", ResolveError { kind: Proto(ProtoError { kind: Io(Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }) }) }))
this is the response by the http_client
Response: Method - POST Url - http://localhost:3000/api/webhooks/my_webhool - Status 502 - Headers - Headers({'content-length': '44', 'date': 'Mon, 15 Aug 2022 04:33:51 GMT'})
I'm processing a queue of messages where each message contains a Discord Webook for its destination (these webhooks are from different accounts that are not owned by myself.)
Pulling the Docker image on M1 results in the following error:
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest sha256:ee6bba64bdc0a774b736115acedab65eb18ae4f75a0aa06d64c3625cb2f87153: not found
If you need a hand with testing patches for this, I'm around on Discord (JakeMakesStuff#0001). ๐
Now that the issues #16 is finished what is the correct way in which I can use proxy with several discord applications?
I'm on a M1 mac so I wasn't able to get it to work via docker. But I cloned this repo then:
cargo build --release
DISCORD_TOKEN="my token" PORT=3000 ./target/release/twilight-http-proxy
2022-06-22T15:52:23.122150Z INFO twilight_http_proxy: Listening on http://0.0.0.0:3000
Note also that the
README.md
is wrong and the built binary istwilight-http-proxy
rather thantwilight_http_proxy
.
Now I start up my bot using proxy="http://localhost:3000"
and I immediately have issues. In the proxy log I see:
2022-06-22T15:53:40.514419Z ERROR twilight_http_proxy: Unsupported HTTP method in request, CONNECT
And in my bot's log we can see that it's trying to GET /users/@me
:
[...]
File "mybot/env/lib/python3.10/site-packages/discord/http.py", line 561, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "mybot/env/lib/python3.10/site-packages/discord/http.py", line 444, in request
async with self.__session.request(method, url, **kwargs) as response:
File "mybot/env/lib/python3.10/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "mybot/env/lib/python3.10/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "mybot/env/lib/python3.10/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "mybot/env/lib/python3.10/site-packages/aiohttp/connector.py", line 890, in _create_connection
_, proto = await self._create_proxy_connection(req, traces, timeout)
File "mybot/env/lib/python3.10/site-packages/aiohttp/connector.py", line 1124, in _create_proxy_connection
raise ClientHttpProxyError(
aiohttp.client_exceptions.ClientHttpProxyError: 501, message='Not Implemented', url=URL('http://localhost:3000')
It appears that query string parameters are not forwarded to Discord. For example:
GET https://fullchannellink/messages?limit=anything turns to https://fullchannellink/messages
This happens on L239 of main.rs, where request_path uses .path on the request uri, which ditches any querystring stuff.
Currently if the proxy runs into an internal error the connection is just closed without any reply. While with #25 we now have logging for these, this behavior is still far from ideal. In addition the snafu dependency is a bit redundant atm. At the very least we should be giving at least some error and not a connection reset. as this can lead to very unexpected behavior in libraries
We have several options here:
of these option 2 and 3 would probably be the best options
Clients requesting via the proxy may not be specifying a header, because it shouldn't be needed. The bot token is a required environment variable, but isn't actually placed into the headers of requests right now.
The README is partially wrong and some features need to be documented:
Authorization
header set needs to be explained better (multiple clients)This project needs to have similar clippy, check, format, etc CI as the main project.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.