Skip to content

Non-websocket responses created with process_response log "connection rejected (200 OK)" #1606

Open
@sminnee

Description

@sminnee

Scenario

I have a /healthz endpoint on my websocket server, used as a kubernetes health check.

What I expected to happen

If the websocket connection upgrade headers aren't present, then no "connection rejection" message needs be send.

Connection: upgrade
Upgrade: websocket

Relevant code

This code from ServerProtocol.send_response() seems to be the source.

        if response.status_code == 101:
            assert self.state is CONNECTING
            self.state = OPEN
            self.logger.info("connection open")

        else:
            self.logger.info(
                "connection rejected (%d %s)",
                response.status_code,
                response.reason_phrase,
            )

            self.send_eof()
            self.parser = self.discard()
            next(self.parser)  # start coroutine

I expect we could change the second block to only send a message if a boolean websocket_requested parameter was true. That would mean change the method signature, which is a bit of a pain.

Alternatively, we could avoid showing a rejection message for any 200-399 response.

Should I raise a PR?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions