Hook up maxPayloadLength, not for Zlib

This commit is contained in:
Alex Hultman
2018-12-29 13:32:49 +01:00
parent f5583b4a8a
commit 50de2cea89
4 changed files with 13 additions and 8 deletions
+3
View File
@@ -95,6 +95,9 @@ public:
webSocketContext->getExt()->drainHandler = behavior.drain;
webSocketContext->getExt()->closeHandler = behavior.close;
/* Copy settings */
webSocketContext->getExt()->maxPayloadLength = behavior.maxPayloadLength;
return get(pattern, [webSocketContext, this, behavior](auto *res, auto *req) {
/* If we have this header set, it's a websocket */
std::string_view secWebSocketKey = req->getHeader("sec-websocket-key");
+6 -7
View File
@@ -221,14 +221,13 @@ private:
return false;
}
// bug: todo
static bool refusePayloadLength(uint64_t length, uWS::WebSocketState<isServer> *wState) {
static bool refusePayloadLength(uint64_t length, uWS::WebSocketState<isServer> *wState, void *s) {
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) static_dispatch(us_ssl_socket_context_ext, us_socket_context_ext)(
static_dispatch(us_ssl_socket_get_context, us_socket_get_context)((SOCKET_TYPE *)s)
);
//std::cout << "refuse payload length" << std::endl;
/* We check if we want to accept such a frame based on size */
// for now, accept anything
return false;
/* Return true for refuse, false for accept */
return webSocketContextData->maxPayloadLength < length;
}
WebSocketContext<SSL, isServer> *init() {
+3
View File
@@ -32,6 +32,9 @@ struct WebSocketContextData {
std::function<void(WebSocket<SSL, true> *, std::string_view, uWS::OpCode)> messageHandler = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *)> drainHandler = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *, int, std::string_view)> closeHandler = nullptr;
/* Settings for this context */
size_t maxPayloadLength = 0;
};
}
+1 -1
View File
@@ -288,7 +288,7 @@ protected:
}
wState->state.lastFin = isFin(src);
if (Impl::refusePayloadLength(payLength, wState)) {
if (Impl::refusePayloadLength(payLength, wState, user)) {
Impl::forceClose(wState, user);
return true;
}