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

Set Response Headers when Server is denying the client? #1294

Open
unordentlich opened this issue Jan 15, 2023 · 0 comments
Open

Set Response Headers when Server is denying the client? #1294

unordentlich opened this issue Jan 15, 2023 · 0 comments

Comments

@unordentlich
Copy link

Describe what you would like to know or do
I'm denying clients which aren't providing all neccessary information and would like to set a custom Response Header field right here, is there a way for that? So that I can provide an error message, what is missing :)
image

Describe the solution you'd considered
I tried to put a HttpStatusMessage in the Builder´, which didn't work 👀

@Override
    public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket conn, Draft draft,
                                                                       ClientHandshake request) throws InvalidDataException {
        ServerHandshakeBuilder builder = super
                .onWebsocketHandshakeReceivedAsServer(conn, draft, request);

        int success = 0;
        for (int i = 0; i <= 10; i++) {
            String key = Core.getConfiguration().config().getString("socket.authenticator." + i + ".key");
            String value = Core.getConfiguration().config().getString("socket.authenticator." + i + ".value");

            if (key == null || value == null) continue;

            if (!request.hasFieldValue(key)) continue;

            if (request.getFieldValue(key).equals(value)) {
                success++;
            }
        }
        if (success != 11) {
        // HERE I WANT TO SET A CUSTOM HTTP RESPONSE HEADER :)
            throw new InvalidDataException(CloseFrame.POLICY_VALIDATION, "Not accepted");
        }

        return builder;
    }
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

No branches or pull requests

1 participant