Skip to content

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

Open
@unordentlich

Description

@unordentlich

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @unordentlich

        Issue actions

          Set Response Headers when Server is denying the client? · Issue #1294 · TooTallNate/Java-WebSocket