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

Add deflate compressions options to MqttClientWebSocketOptionsBuilder #2127

Merged
merged 4 commits into from
Dec 23, 2024
Merged
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: 3 additions & 0 deletions Source/MQTTnet/Implementations/MqttWebSocketChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ void SetupClientWebSocket(ClientWebSocket clientWebSocket)
}
}

if (_options.DangerousDeflateOptions != null)
clientWebSocket.Options.DangerousDeflateOptions = _options.DangerousDeflateOptions;

// Only set the value if it is actually true. This property is not supported on all platforms
// and will throw a _PlatformNotSupported_ (i.e. WASM) exception when being used regardless of the actual value.
if (_options.UseDefaultCredentials)
Expand Down
1 change: 1 addition & 0 deletions Source/MQTTnet/Options/MqttClientWebSocketOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace MQTTnet;
public sealed class MqttClientWebSocketOptions : IMqttClientChannelOptions
{
public CookieContainer CookieContainer { get; set; }
public WebSocketDeflateOptions DangerousDeflateOptions { get; set; }

public ICredentials Credentials { get; set; }

Expand Down
13 changes: 13 additions & 0 deletions Source/MQTTnet/Options/MqttClientWebSocketOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.WebSockets;

namespace MQTTnet;

Expand All @@ -23,6 +24,18 @@ public MqttClientWebSocketOptionsBuilder WithCookieContainer(CookieContainer coo
return this;
}

/// <summary>
/// Allows the client to negotiate deflate compression on every message, by using the permessage-deflate WebSocket extension.
/// This adds the Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits header.
/// </summary>
/// <param name="dangerousDeflateOptions"></param>
/// <returns></returns>
public MqttClientWebSocketOptionsBuilder WithDangerousDeflateOptions(WebSocketDeflateOptions dangerousDeflateOptions)
{
_webSocketOptions.DangerousDeflateOptions = dangerousDeflateOptions;
return this;
}

public MqttClientWebSocketOptionsBuilder WithCookieContainer(ICredentials credentials)
{
_webSocketOptions.Credentials = credentials;
Expand Down
Loading