Commit 6cd7b9ca authored by Damien Arrachequesne's avatar Damien Arrachequesne Committed by Alex Hultman

restore the maxPayload option (#573)

* restore the maxPayload option

* fix test

* move to Group
parent 59939287
......@@ -118,7 +118,7 @@ void Group<isServer>::removeWebSocket(WebSocket<isServer> *webSocket) {
}
template <bool isServer>
Group<isServer>::Group(int extensionOptions, Hub *hub, uS::NodeData *nodeData) : uS::NodeData(*nodeData), hub(hub), extensionOptions(extensionOptions) {
Group<isServer>::Group(int extensionOptions, unsigned int maxPayload, Hub *hub, uS::NodeData *nodeData) : uS::NodeData(*nodeData), maxPayload(maxPayload), hub(hub), extensionOptions(extensionOptions) {
connectionHandler = [](WebSocket<isServer> *, HttpRequest) {};
transferHandler = [](WebSocket<isServer> *) {};
messageHandler = [](WebSocket<isServer> *, char *, size_t, OpCode) {};
......
......@@ -41,6 +41,7 @@ protected:
Hub *hub;
int extensionOptions;
unsigned int maxPayload;
Timer *timer = nullptr, *httpTimer = nullptr;
std::string userPingMessage;
std::stack<Poll *> iterators;
......@@ -59,7 +60,7 @@ protected:
void addHttpSocket(HttpSocket<isServer> *httpSocket);
void removeHttpSocket(HttpSocket<isServer> *httpSocket);
Group(int extensionOptions, Hub *hub, uS::NodeData *nodeData);
Group(int extensionOptions, unsigned int maxPayload, Hub *hub, uS::NodeData *nodeData);
void stopListening();
public:
......
......@@ -29,8 +29,8 @@ protected:
public:
template <bool isServer>
Group<isServer> *createGroup(int extensionOptions = 0) {
return new Group<isServer>(extensionOptions, this, nodeData);
Group<isServer> *createGroup(int extensionOptions = 0, unsigned int maxPayload = 16777216) {
return new Group<isServer>(extensionOptions, maxPayload, this, nodeData);
}
template <bool isServer>
......@@ -43,8 +43,8 @@ public:
void connect(std::string uri, void *user = nullptr, std::map<std::string, std::string> extraHeaders = {}, int timeoutMs = 5000, Group<CLIENT> *eh = nullptr);
void upgrade(uv_os_sock_t fd, const char *secKey, SSL *ssl, const char *extensions, size_t extensionsLength, const char *subprotocol, size_t subprotocolLength, Group<SERVER> *serverGroup = nullptr);
Hub(int extensionOptions = 0, bool useDefaultLoop = false) : uS::Node(LARGE_BUFFER_SIZE, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_PRE_PADDING, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_POST_PADDING, useDefaultLoop),
Group<SERVER>(extensionOptions, this, nodeData), Group<CLIENT>(0, this, nodeData) {
Hub(int extensionOptions = 0, bool useDefaultLoop = false, unsigned int maxPayload = 16777216) : uS::Node(LARGE_BUFFER_SIZE, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_PRE_PADDING, WebSocketProtocol<SERVER, WebSocket<SERVER>>::CONSUME_POST_PADDING, useDefaultLoop),
Group<SERVER>(extensionOptions, maxPayload, this, nodeData), Group<CLIENT>(0, maxPayload, this, nodeData) {
inflateInit2(&inflationStream, -15);
inflationBuffer = new char[LARGE_BUFFER_SIZE];
......
......@@ -32,7 +32,8 @@ protected:
using uS::Socket::closeSocket;
static bool refusePayloadLength(uint64_t length, WebSocketState<isServer> *webSocketState) {
return length > 16777216;
WebSocket<isServer> *webSocket = static_cast<WebSocket<isServer> *>(webSocketState);
return length > Group<isServer>::from(webSocket)->maxPayload;
}
static bool setCompressed(WebSocketState<isServer> *webSocketState) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment