Giter Club home page Giter Club logo

http-proxy's People

Contributors

7596ff avatar aenterprise avatar beyazit avatar drklee3 avatar erk- avatar gelbpunkt avatar liminalitythree avatar rxdn avatar siriscmv avatar vilgotf avatar zeylahellyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http-proxy's Issues

Handle unknown paths

At the moment the proxy will break if presented with a new unknown path.

We should be able to handle it in some way.

Slash commands support doesn't exist in proxy

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.

Using with Discord webhooks

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 Twilight Docker image fails on M1

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). ๐Ÿ‘

Use with discord.py bot

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 is twilight-http-proxy rather than twilight_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')

Improve error behavior

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:

  1. Return an 400 bad request, this has the clear disadvantage that downstream consumers might try to parse the body as a discord error and fail very badly, potentially crashing them
  2. return a generic 500 server error
  3. return a 503 service unavailable

of these option 2 and 3 would probably be the best options

monitoring multiple bots

I need to monitor several discord tokens with the http proxy, is there any possibility of this if implemented?

image

[forward] send authorization header from state

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.

Redo documentation

The README is partially wrong and some features need to be documented:

  • The http-proxy is not a "real" HTTP proxy, the ruby example needs to be removed and replaced with maybe a curl example
  • Behaviour with Authorization header set needs to be explained better (multiple clients)
  • API v8/v6 images should no longer be mentioned, latest supports all versions as long as the Path exists in twilight
  • Metrics shouldn't be documented as "Grafana metrics", rather as "Prometheus metrics" since Grafana also supports e.g. InfluxDB as a backend
  • After tackling #26, document this behavior properly

Add CI

This project needs to have similar clippy, check, format, etc CI as the main project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.