Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pluiedev opened this issue Aug 11, 2021 · 5 comments
Closed

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

pluiedev opened this issue Aug 11, 2021 · 5 comments
Assignees
Labels
Type: Enhancement Improvements to existing features.

Comments

@pluiedev
Copy link

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
Copy link

boring-cyborg bot commented Aug 11, 2021

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:

  • Most importantly, all issues must adhere to our Code of Conduct. Please give it a quick read if you haven't already.

  • While our team is passionate about the projects we've created here, we're all volunteers. Please don't be offended if it takes time for us to get to your issue - we'll be here as soonas we can be!

  • Please provide as much information as possible when asking a question, reporting a problem, or submitting a feature request. This will help us to address your issue quickly and efficiently. If you forgot to add some information, no worries - feel free to edit the issue and add anything you missed!

    Thanks for contacting us! If you have any further questions, please feel free to join us on Discord in the #dev-kotdis channel (or #kordex-discussion for Kord Extensions projects), or to contact a staff member directly.

@gdude2002 gdude2002 self-assigned this Aug 11, 2021
@gdude2002 gdude2002 added the Type: Enhancement Improvements to existing features. label Aug 11, 2021
@gdude2002
Copy link
Member

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
Copy link

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

@pluiedev
Copy link
Author

pluiedev commented Aug 13, 2021

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvements to existing features.
Projects
None yet
Development

No branches or pull requests

3 participants