Hook up maxPayloadLength, not for Zlib
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user