Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebSocketDecoderConfig not final #13601

Open
wants to merge 1 commit into
base: 4.1
Choose a base branch
from

Conversation

faceless2
Copy link

Motivation:

WebSocketDecoderConfig is currently final, which means that some aspects (eg maxFramePayloadLength) cannot be changed as a result of - for example - an Authorization header sent with the initial handshake, or with some sort of initial "login" websocket message.

I can't see any reason why this field in particular has to be final; it's not like the value for one received frame has to be identical to a frame received for a different message.

Modification:

I've made the class non-final so it can be extended, but - because there is a builder class - I've made the new zero-argument constructor protected, so it can only be called by someone explicitly subclassing this class.

Result:

Addresses #13600

@normanmaurer
Copy link
Member

I dont understand why this is needed... do you want to change things on the fly ?

@faceless2
Copy link
Author

faceless2 commented Sep 15, 2023

Yes, exactly. The initial limit of 65535 (bytes in a frame) may need to be raised after authentication.

@normanmaurer
Copy link
Member

Can you show me how you would do this with the api change ?

@faceless2
Copy link
Author

Certainly. This is extracted from a patched version, which I've been running here successfully.

// In the ChannelInitializer.initChannel() code, adding the various handlers to the ChannelPipeline
MyWebSocketDecoderConfig config = new MyWebSocketDecoderConfig();
pipeline.addLast(new WebSocketServerProtocolHandler(contextPath, null, false, false, 10000, config);
pipeline.addLast(new MyWebsocketHandler(engine, processorPool, config));

// MyWebsocketHandler is a SimpleChannelInboundHandler<WebsocketFrame>
// it processes the WebSocket messages and can call config.setMaxFramePayloadLength(...)
// when it's able to authenticate the session, ie. after receiving a "login" message.

// Finally MyWebSocketDecoderConfig
private static class MyWebSocketDecoderConfig extends WebSocketDecoderConfig {
    private int maxFramePayloadLength;
    MyWebSocketDecoderConfig() {
        super();
        maxFramePayloadLength = super.maxFramePayloadLength();
    }
    @Override public int maxFramePayloadLength() {
        return maxFramePayloadLength;
    }
    public void setMaxFramePayloadLength(int len) {
        maxFramePayloadLength = len;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants