Skip to content
New issue

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

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

Already on GitHub? # to your account

Add the ability to set a proxy #23

Closed
wants to merge 2 commits into from
Closed

Add the ability to set a proxy #23

wants to merge 2 commits into from

Conversation

KrisQuack
Copy link

A fix for issue #20 that I have been experiencing myself. Seems Bing has a limit of 300 conversations a day and will block your IP if you reach that limit. Changing IP of the request via a proxy fixes this and avoids routing the whole system which may be problematic.

Let me know if you think this should be done a different way, I tried to follow the projects style :)

@@ -68,7 +68,8 @@ public async Task<BingChatConversation> CreateConversation()
if (cookies.Count == 0)
cookies.Add(new Uri("https://www.bing.com"), new Cookie("_U", Utils.GenerateRandomHexString()));

using var handler = new HttpClientHandler { CookieContainer = cookies };
using var handler = new HttpClientHandler
{ CookieContainer = cookies, Proxy = _options.Proxy, UseProxy = _options.Proxy != null };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, according to documentation, you do not need to set UseProxy property because it is true by default and this change would alter the behavior.

Ref: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.useproxy

@neon-sunset
Copy link
Collaborator

neon-sunset commented Jun 6, 2023

Also, I just realized that this PR would not work as is because it is also necessary to set proxy to SignalR connection factory.
For that, you will need to forward configuration or proxy to BingChatConversation constructor and make ConnectionFactory an instance field that captures it.

See https://github.com/bsdayo/BingChat/blob/main/src/BingChat/BingChatConversation.cs#L21

@KrisQuack KrisQuack closed this Jun 23, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants