(WebSocketServer) add option to disable deflate compression, exposed with the -x option to ws echo_server
This commit is contained in:
parent
111475e65c
commit
4c66a7561e
@ -1,6 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [8.1.2] - 2020-02-18
|
||||||
|
|
||||||
|
(WebSocketServer) add option to disable deflate compression, exposed with the -x option to ws echo_server
|
||||||
|
|
||||||
## [8.1.1] - 2020-02-18
|
## [8.1.1] - 2020-02-18
|
||||||
|
|
||||||
(ws cobra to statsd and sentry sender) exit if no messages are received for one minute, which is a sign that something goes wrong on the server side. That should be changed to be configurable in the future
|
(ws cobra to statsd and sentry sender) exit if no messages are received for one minute, which is a sign that something goes wrong on the server side. That should be changed to be configurable in the future
|
||||||
|
@ -42,7 +42,8 @@ namespace
|
|||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
HttpServer::HttpServer(int port, const std::string& host, int backlog, size_t maxConnections, int addressFamily)
|
HttpServer::HttpServer(
|
||||||
|
int port, const std::string& host, int backlog, size_t maxConnections, int addressFamily)
|
||||||
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
||||||
, _connectedClientsCount(0)
|
, _connectedClientsCount(0)
|
||||||
{
|
{
|
||||||
|
@ -23,11 +23,8 @@ namespace ix
|
|||||||
const size_t SocketServer::kDefaultMaxConnections(32);
|
const size_t SocketServer::kDefaultMaxConnections(32);
|
||||||
const int SocketServer::kDefaultAddressFamily(AF_INET);
|
const int SocketServer::kDefaultAddressFamily(AF_INET);
|
||||||
|
|
||||||
SocketServer::SocketServer(int port,
|
SocketServer::SocketServer(
|
||||||
const std::string& host,
|
int port, const std::string& host, int backlog, size_t maxConnections, int addressFamily)
|
||||||
int backlog,
|
|
||||||
size_t maxConnections,
|
|
||||||
int addressFamily)
|
|
||||||
: _port(port)
|
: _port(port)
|
||||||
, _host(host)
|
, _host(host)
|
||||||
, _backlog(backlog)
|
, _backlog(backlog)
|
||||||
@ -97,7 +94,8 @@ namespace ix
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "SocketServer::listen() error calling inet_pton "
|
ss << "SocketServer::listen() error calling inet_pton "
|
||||||
<< "at address " << _host << ":" << _port << " : " << strerror(Socket::getErrno());
|
<< "at address " << _host << ":" << _port << " : "
|
||||||
|
<< strerror(Socket::getErrno());
|
||||||
|
|
||||||
Socket::closeSocket(_serverFd);
|
Socket::closeSocket(_serverFd);
|
||||||
return std::make_pair(false, ss.str());
|
return std::make_pair(false, ss.str());
|
||||||
@ -108,7 +106,8 @@ namespace ix
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "SocketServer::listen() error calling bind "
|
ss << "SocketServer::listen() error calling bind "
|
||||||
<< "at address " << _host << ":" << _port << " : " << strerror(Socket::getErrno());
|
<< "at address " << _host << ":" << _port << " : "
|
||||||
|
<< strerror(Socket::getErrno());
|
||||||
|
|
||||||
Socket::closeSocket(_serverFd);
|
Socket::closeSocket(_serverFd);
|
||||||
return std::make_pair(false, ss.str());
|
return std::make_pair(false, ss.str());
|
||||||
@ -124,7 +123,8 @@ namespace ix
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "SocketServer::listen() error calling inet_pton "
|
ss << "SocketServer::listen() error calling inet_pton "
|
||||||
<< "at address " << _host << ":" << _port << " : " << strerror(Socket::getErrno());
|
<< "at address " << _host << ":" << _port << " : "
|
||||||
|
<< strerror(Socket::getErrno());
|
||||||
|
|
||||||
Socket::closeSocket(_serverFd);
|
Socket::closeSocket(_serverFd);
|
||||||
return std::make_pair(false, ss.str());
|
return std::make_pair(false, ss.str());
|
||||||
@ -135,7 +135,8 @@ namespace ix
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "SocketServer::listen() error calling bind "
|
ss << "SocketServer::listen() error calling bind "
|
||||||
<< "at address " << _host << ":" << _port << " : " << strerror(Socket::getErrno());
|
<< "at address " << _host << ":" << _port << " : "
|
||||||
|
<< strerror(Socket::getErrno());
|
||||||
|
|
||||||
Socket::closeSocket(_serverFd);
|
Socket::closeSocket(_serverFd);
|
||||||
return std::make_pair(false, ss.str());
|
return std::make_pair(false, ss.str());
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
#include "IXWebSocketSendInfo.h"
|
#include "IXWebSocketSendInfo.h"
|
||||||
#include "IXWebSocketTransport.h"
|
#include "IXWebSocketTransport.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <condition_variable>
|
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "IXUserAgent.h"
|
#include "IXUserAgent.h"
|
||||||
#include "libwshandshake.hpp"
|
#include "libwshandshake.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -335,8 +336,9 @@ namespace ix
|
|||||||
std::string header = headers["sec-websocket-extensions"];
|
std::string header = headers["sec-websocket-extensions"];
|
||||||
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(header);
|
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(header);
|
||||||
|
|
||||||
// If the client has requested that extension, enable it.
|
// If the client has requested that extension,
|
||||||
if (webSocketPerMessageDeflateOptions.enabled())
|
// and the server does not prevent it, enable it.
|
||||||
|
if (_enablePerMessageDeflate && webSocketPerMessageDeflateOptions.enabled())
|
||||||
{
|
{
|
||||||
_enablePerMessageDeflate = true;
|
_enablePerMessageDeflate = true;
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ namespace ix
|
|||||||
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
||||||
, _handshakeTimeoutSecs(handshakeTimeoutSecs)
|
, _handshakeTimeoutSecs(handshakeTimeoutSecs)
|
||||||
, _enablePong(kDefaultEnablePong)
|
, _enablePong(kDefaultEnablePong)
|
||||||
|
, _enablePerMessageDeflate(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +60,11 @@ namespace ix
|
|||||||
_enablePong = false;
|
_enablePong = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocketServer::disablePerMessageDeflate()
|
||||||
|
{
|
||||||
|
_enablePerMessageDeflate = false;
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocketServer::setOnConnectionCallback(const OnConnectionCallback& callback)
|
void WebSocketServer::setOnConnectionCallback(const OnConnectionCallback& callback)
|
||||||
{
|
{
|
||||||
_onConnectionCallback = callback;
|
_onConnectionCallback = callback;
|
||||||
@ -73,9 +79,18 @@ namespace ix
|
|||||||
webSocket->disableAutomaticReconnection();
|
webSocket->disableAutomaticReconnection();
|
||||||
|
|
||||||
if (_enablePong)
|
if (_enablePong)
|
||||||
|
{
|
||||||
webSocket->enablePong();
|
webSocket->enablePong();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
webSocket->disablePong();
|
webSocket->disablePong();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_enablePerMessageDeflate)
|
||||||
|
{
|
||||||
|
webSocket->disablePerMessageDeflate();
|
||||||
|
}
|
||||||
|
|
||||||
// Add this client to our client set
|
// Add this client to our client set
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,7 @@ namespace ix
|
|||||||
|
|
||||||
void enablePong();
|
void enablePong();
|
||||||
void disablePong();
|
void disablePong();
|
||||||
|
void disablePerMessageDeflate();
|
||||||
|
|
||||||
void setOnConnectionCallback(const OnConnectionCallback& callback);
|
void setOnConnectionCallback(const OnConnectionCallback& callback);
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ namespace ix
|
|||||||
// Member variables
|
// Member variables
|
||||||
int _handshakeTimeoutSecs;
|
int _handshakeTimeoutSecs;
|
||||||
bool _enablePong;
|
bool _enablePong;
|
||||||
|
bool _enablePerMessageDeflate;
|
||||||
|
|
||||||
OnConnectionCallback _onConnectionCallback;
|
OnConnectionCallback _onConnectionCallback;
|
||||||
|
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "8.1.1"
|
#define IX_WEBSOCKET_VERSION "8.1.2"
|
||||||
|
12
ws/ws.cpp
12
ws/ws.cpp
@ -174,6 +174,7 @@ int main(int argc, char** argv)
|
|||||||
echoServerApp->add_option("--host", hostname, "Hostname");
|
echoServerApp->add_option("--host", hostname, "Hostname");
|
||||||
echoServerApp->add_flag("-g", greetings, "Verbose");
|
echoServerApp->add_flag("-g", greetings, "Verbose");
|
||||||
echoServerApp->add_flag("-6", ipv6, "IpV6");
|
echoServerApp->add_flag("-6", ipv6, "IpV6");
|
||||||
|
echoServerApp->add_flag("-x", disablePerMessageDeflate, "Disable per message deflate");
|
||||||
addTLSOptions(echoServerApp);
|
addTLSOptions(echoServerApp);
|
||||||
|
|
||||||
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
|
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
|
||||||
@ -336,8 +337,12 @@ int main(int argc, char** argv)
|
|||||||
addTLSOptions(proxyServerApp);
|
addTLSOptions(proxyServerApp);
|
||||||
|
|
||||||
CLI::App* minidumpApp = app.add_subcommand("upload_minidump", "Upload a minidump to sentry");
|
CLI::App* minidumpApp = app.add_subcommand("upload_minidump", "Upload a minidump to sentry");
|
||||||
minidumpApp->add_option("--minidump", minidump, "Minidump path")->required()->check(CLI::ExistingPath);
|
minidumpApp->add_option("--minidump", minidump, "Minidump path")
|
||||||
minidumpApp->add_option("--metadata", metadata, "Metadata path")->required()->check(CLI::ExistingPath);
|
->required()
|
||||||
|
->check(CLI::ExistingPath);
|
||||||
|
minidumpApp->add_option("--metadata", metadata, "Metadata path")
|
||||||
|
->required()
|
||||||
|
->check(CLI::ExistingPath);
|
||||||
minidumpApp->add_option("--project", project, "Sentry Project")->required();
|
minidumpApp->add_option("--project", project, "Sentry Project")->required();
|
||||||
minidumpApp->add_option("--key", key, "Sentry Key")->required();
|
minidumpApp->add_option("--key", key, "Sentry Key")->required();
|
||||||
minidumpApp->add_flag("-v", verbose, "Verbose");
|
minidumpApp->add_flag("-v", verbose, "Verbose");
|
||||||
@ -394,7 +399,8 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (app.got_subcommand("echo_server"))
|
else if (app.got_subcommand("echo_server"))
|
||||||
{
|
{
|
||||||
ret = ix::ws_echo_server_main(port, greetings, hostname, tlsOptions, ipv6);
|
ret = ix::ws_echo_server_main(
|
||||||
|
port, greetings, hostname, tlsOptions, ipv6, disablePerMessageDeflate);
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("broadcast_server"))
|
else if (app.got_subcommand("broadcast_server"))
|
||||||
{
|
{
|
||||||
|
3
ws/ws.h
3
ws/ws.h
@ -30,7 +30,8 @@ namespace ix
|
|||||||
bool greetings,
|
bool greetings,
|
||||||
const std::string& hostname,
|
const std::string& hostname,
|
||||||
const ix::SocketTLSOptions& tlsOptions,
|
const ix::SocketTLSOptions& tlsOptions,
|
||||||
bool ipv6);
|
bool ipv6,
|
||||||
|
bool disablePerMessageDeflate);
|
||||||
|
|
||||||
int ws_broadcast_server_main(int port,
|
int ws_broadcast_server_main(int port,
|
||||||
const std::string& hostname,
|
const std::string& hostname,
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <ixwebsocket/IXDNSLookup.h>
|
||||||
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
|
||||||
#include <ixwebsocket/IXDNSLookup.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ixwebsocket/IXWebSocketServer.h>
|
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
|
#include <ixwebsocket/IXWebSocketServer.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -15,7 +15,8 @@ namespace ix
|
|||||||
bool greetings,
|
bool greetings,
|
||||||
const std::string& hostname,
|
const std::string& hostname,
|
||||||
const ix::SocketTLSOptions& tlsOptions,
|
const ix::SocketTLSOptions& tlsOptions,
|
||||||
bool ipv6)
|
bool ipv6,
|
||||||
|
bool disablePerMessageDeflate)
|
||||||
{
|
{
|
||||||
spdlog::info("Listening on {}:{}", hostname, port);
|
spdlog::info("Listening on {}:{}", hostname, port);
|
||||||
|
|
||||||
@ -28,6 +29,12 @@ namespace ix
|
|||||||
|
|
||||||
server.setTLSOptions(tlsOptions);
|
server.setTLSOptions(tlsOptions);
|
||||||
|
|
||||||
|
if (disablePerMessageDeflate)
|
||||||
|
{
|
||||||
|
spdlog::info("Disable per message deflate");
|
||||||
|
server.disablePerMessageDeflate();
|
||||||
|
}
|
||||||
|
|
||||||
server.setOnConnectionCallback(
|
server.setOnConnectionCallback(
|
||||||
[greetings](std::shared_ptr<ix::WebSocket> webSocket,
|
[greetings](std::shared_ptr<ix::WebSocket> webSocket,
|
||||||
std::shared_ptr<ConnectionState> connectionState) {
|
std::shared_ptr<ConnectionState> connectionState) {
|
||||||
|
Loading…
Reference in New Issue
Block a user