Kord-Extensions / kord-extensions

Kord extensions framework, providing commands and distinct units of functionality
https://kordex.dev
European Union Public License 1.2
112 stars 27 forks source link

Allow selecting a custom HTTP engine for Kord (niche request!) #69

Closed pluiedev closed 3 years ago

pluiedev commented 3 years ago

Summary

Currently I have a (very) niche problem whenever I want to test or run my bot -- turns out that Kord defaults to use CIO for its default HTTP engine for Ktor, which has some bizarre issues with my proxy service that made the outward packets not handled by the proxy service. After some research I found out that my proxy is running under SOCKS, while CIO and Apache engines only support HTTP proxies for some godforsaken reasons.

After some more research I found out that Ktor also supports the Java HTTP Client, which fully supports SOCKS proxies and after using some (concerning) hacks I was able to get it to work.

Current Behaviour

The HTTP client is hardwired to use CIO, which is undesirable for my needs as mentioned above.

Preferred Behaviour

Allow a field to be exposed in ExtensionBotBuilder, either of type HttpClient or HttpClientEngineFactory<*> to set customize the HTTP client or its engine. The latter may require modifying Ktor, but from what I can see, modifying HttpClient is perfectly acceptable within Ktor's APIs, as a KordBuilder can be specified to take a custom client, while all of the normal settings required to make it work still applies.

Suggestions

I noticed that only a selection of settings are customizable in ExtensionBotBuilder, presumably due to encapsulation concerns. But in addition to the ability to customize HTTP clients (which is arguably niche), I don't see why the KordBuilder cannot be customized with a configure function (like KordBuilder.() -> Unit). That would solve the entire problem, and may even prevent future problems like this showing up.

Media

Current workaround Current workaround for this issue; some parts are redacted and/or deleted
boring-cyborg[bot] commented 3 years ago

Hello, and thanks for opening an issue! As this is the first time you've created an issue on this repository, we'd just like to offer you a warm welcome to the project, and the following pointers:

gdude2002 commented 3 years ago

If Kord provides something for this, then I suspect it should be pretty easy to expose that, right? Can't imagine this being difficult.

HopeBaron commented 3 years ago

Kord allows setting httpClient in KordBuilder as long as it could install Websockets and JsonFeature

pluiedev commented 3 years ago

Kord allows setting httpClient in KordBuilder as long as it could install Websockets and JsonFeature

Yeah that's what I did with the workaround. If I can do that with Kordex without duplicating a lot of code that would be good

Side note I just found out that this is the 69th issue! Nice.
gdude2002 commented 3 years ago

Instead of providing a direct abstraction for this, I'm adding a kord DSL function to the ExtensibleBotBuilder class. This will allow you to directly run code against the KordBuilder, which I think is a more future-proof solution for allowing users to customize Kord's behaviour.

This will be available in the next snapshot, but I'm hoping to get a release out soon!

Also: Nice.