add configurable headers, bump v

This commit is contained in:
Elijah R 2024-04-24 16:20:35 -04:00
parent 7117823772
commit d322c315dd
2 changed files with 7 additions and 2 deletions

View file

@ -42,6 +42,7 @@ public class CollabVMClient {
private Dictionary<string, Action<string, string[]>> commandsSeparatedArgs; private Dictionary<string, Action<string, string[]>> commandsSeparatedArgs;
private Dictionary<string, Action<string, string>> commandsOneArg; private Dictionary<string, Action<string, string>> commandsOneArg;
private bool _usesAccountAuth; private bool _usesAccountAuth;
private Dictionary<string,string> _headers;
// Tasks and related // Tasks and related
private TaskCompletionSource<Node[]> GotNodeList; private TaskCompletionSource<Node[]> GotNodeList;
private TaskCompletionSource<bool> GotConnectionToNode; private TaskCompletionSource<bool> GotConnectionToNode;
@ -91,7 +92,8 @@ public class CollabVMClient {
/// <param name="username">Username to join the VM as. If null, the server will assign a guest name.</param> /// <param name="username">Username to join the VM as. If null, the server will assign a guest name.</param>
/// <param name="node">Node to connect to. If null, a VM will not be automatically joined.</param> /// <param name="node">Node to connect to. If null, a VM will not be automatically joined.</param>
/// <param name="proxy">HTTP proxy to connect with. If null, a proxy will not be used.</param> /// <param name="proxy">HTTP proxy to connect with. If null, a proxy will not be used.</param>
public CollabVMClient(string url, string? username = null, string? node = null, string? proxy = null) { /// <param name="headers">Additional headers to use when connecting to the server.</param>
public CollabVMClient(string url, string? username = null, string? node = null, string? proxy = null, Dictionary<string,string>? headers = null) {
if (!Uri.TryCreate(url, UriKind.Absolute, out this.url)) { if (!Uri.TryCreate(url, UriKind.Absolute, out this.url)) {
throw new UriFormatException("An invalid URI string was passed."); throw new UriFormatException("An invalid URI string was passed.");
} }
@ -110,6 +112,8 @@ public class CollabVMClient {
this.framebuffer = new Image<Rgba32>(1, 1); this.framebuffer = new Image<Rgba32>(1, 1);
this.socket = new(); this.socket = new();
this.socket.Options.AddSubProtocol("guacamole"); this.socket.Options.AddSubProtocol("guacamole");
this._headers = headers ?? new();
foreach (var header in _headers) this.socket.Options.SetRequestHeader(header.Key, header.Value);
this.socket.Options.SetRequestHeader("Origin", "https://computernewb.com"); this.socket.Options.SetRequestHeader("Origin", "https://computernewb.com");
if (proxy != null) { if (proxy != null) {
this._proxy = new WebProxy(proxy); this._proxy = new WebProxy(proxy);
@ -510,6 +514,7 @@ public class CollabVMClient {
this.NOPRecieve.Interval = 10000; this.NOPRecieve.Interval = 10000;
this.socket = new(); this.socket = new();
this.socket.Options.AddSubProtocol("guacamole"); this.socket.Options.AddSubProtocol("guacamole");
foreach (var header in _headers) this.socket.Options.SetRequestHeader(header.Key, header.Value);
this.socket.Options.SetRequestHeader("Origin", "https://computernewb.com"); this.socket.Options.SetRequestHeader("Origin", "https://computernewb.com");
if (_proxy != null) { if (_proxy != null) {
this.socket.Options.Proxy = this._proxy; this.socket.Options.Proxy = this._proxy;

View file

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<Version>2.5.0</Version> <Version>2.6.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>CollabVMSharp</Title> <Title>CollabVMSharp</Title>
</PropertyGroup> </PropertyGroup>