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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BingChat/BingChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

using var client = new HttpClient(handler);
var headers = client.DefaultRequestHeaders;

Expand Down
9 changes: 8 additions & 1 deletion src/BingChat/BingChatClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BingChat;
using System.Net;

namespace BingChat;

public enum BingChatTone : int
{
Expand Down Expand Up @@ -32,4 +34,9 @@ public sealed class BingChatClientOptions
/// Tone used for conversation (Default: Balanced)
/// </summary>
public BingChatTone Tone { get; set; }

/// <summary>
/// Optional Proxy used for requests
/// </summary>
public WebProxy? Proxy { get; set; }
}