1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 02:03:13 +02:00

relay: add option relay.network.websocket_permessage_deflate

This commit is contained in:
Sébastien Helleu
2024-06-01 12:58:17 +02:00
parent b5b063a836
commit e39a309365
19 changed files with 246 additions and 70 deletions
@@ -34,6 +34,7 @@
#include "../../../weechat-plugin.h"
#include "../../relay.h"
#include "../../relay-auth.h"
#include "../../relay-config.h"
#include "../../relay-http.h"
#include "../../relay-raw.h"
#include "../../relay-remote.h"
@@ -642,7 +643,7 @@ relay_remote_network_connect_ws_auth (struct t_relay_remote *remote)
{
char *password, *totp_secret, *totp;
char *salt_password, salt[64], str_auth[4096], str_auth_base64[4096];
char str_http[8192], str_totp[128];
char str_http[8192], str_totp[128], str_extensions[256];
char hash[512 / 8], hash_hexa[((512 / 8) * 2) + 1];
char ws_key[16], ws_key_base64[64];
int hash_size;
@@ -654,6 +655,7 @@ relay_remote_network_connect_ws_auth (struct t_relay_remote *remote)
totp_secret = NULL;
str_auth[0] = '\0';
str_totp[0] = '\0';
str_extensions[0] = '\0';
password = weechat_string_eval_expression (
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_PASSWORD]),
@@ -744,6 +746,15 @@ relay_remote_network_connect_ws_auth (struct t_relay_remote *remote)
}
}
/* add supported extensions */
if (weechat_config_boolean (relay_config_network_websocket_permessage_deflate))
{
snprintf (str_extensions, sizeof (str_extensions),
"%s",
"Sec-WebSocket-Extensions: permessage-deflate; "
"client_max_window_bits\r\n");
}
snprintf (
str_http, sizeof (str_http),
"GET /api HTTP/1.1\r\n"
@@ -753,12 +764,13 @@ relay_remote_network_connect_ws_auth (struct t_relay_remote *remote)
"Sec-WebSocket-Key: %s\r\n"
"Connection: Upgrade\r\n"
"Upgrade: websocket\r\n"
"Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n"
"%s"
"Host: %s:%d\r\n"
"\r\n",
str_auth_base64,
str_totp,
ws_key_base64,
str_extensions,
remote->address,
remote->port);
relay_remote_network_send (remote, RELAY_MSG_STANDARD,
+14
View File
@@ -92,6 +92,7 @@ struct t_config_option *relay_config_network_tls_priorities = NULL;
struct t_config_option *relay_config_network_totp_secret = NULL;
struct t_config_option *relay_config_network_totp_window = NULL;
struct t_config_option *relay_config_network_websocket_allowed_origins = NULL;
struct t_config_option *relay_config_network_websocket_permessage_deflate = NULL;
/* relay config, irc section */
@@ -1754,6 +1755,19 @@ relay_config_init ()
NULL, NULL, NULL,
&relay_config_change_network_websocket_allowed_origins, NULL, NULL,
NULL, NULL, NULL);
relay_config_network_websocket_permessage_deflate = weechat_config_new_option (
relay_config_file, relay_config_section_network,
"websocket_permessage_deflate", "boolean",
N_("enable websocket extension \"permessage-deflate\" to compress "
"websocket frames, with weechat and api protocols; if disabled, "
"WeeChat (as server) will not enable permessage-deflate even if "
"the client supports it, and when connecting to a remote WeeChat "
"(api relay only), permessage-deflate support is not advertised "
"by WeeChat; it is recommended to keep this option enabled, "
"and you should disable it only if you have troubles with this "
"extension, either with WeeChat or the client"),
NULL, 0, 100, "on", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
/* section irc */
+1
View File
@@ -61,6 +61,7 @@ extern struct t_config_option *relay_config_network_tls_priorities;
extern struct t_config_option *relay_config_network_totp_secret;
extern struct t_config_option *relay_config_network_totp_window;
extern struct t_config_option *relay_config_network_websocket_allowed_origins;
extern struct t_config_option *relay_config_network_websocket_permessage_deflate;
extern struct t_config_option *relay_config_irc_backlog_max_minutes;
extern struct t_config_option *relay_config_irc_backlog_max_number;
+1 -1
View File
@@ -315,7 +315,7 @@ relay_websocket_parse_extensions (const char *extensions,
params = weechat_string_split (exts[i], ";", " ", 0, 0, &num_params);
if (params && (num_params >= 1)
&& (strcmp (params[0], "permessage-deflate") == 0)
&& (weechat_config_integer (relay_config_network_compression) > 0))
&& (weechat_config_boolean (relay_config_network_websocket_permessage_deflate)))
{
ws_deflate->enabled = 1;
ws_deflate->server_context_takeover = 1;