fastly / pushpin

A proxy server for adding push to your API, used at the core of Fastly's Fanout service
https://pushpin.org
Apache License 2.0
3.6k stars 149 forks source link

Respond to websocket pings #47696

Open jkarneges opened 3 years ago

jkarneges commented 3 years ago

It would be nice if Pushpin could automatically respond to ping messages rather than forwarding to the backend. Ideally this would work for not just literal PING frames, but also TEXT frames with ping-like content. Messages not considered to be pings should still be forwarded to the backend for handling.

jkarneges commented 3 years ago

One way to achieve this in a generic way could be to introduce an "auto response" feature. The backend could send a control message telling Pushpin how to identify a certain kind of message, and what to respond with if such a message is identified. Then that feature could be used to set up an auto response for messages identified as pings.

The tricky part would be specifying how to identify messages. For an initial version, perhaps we could support only JSON content, and use something like JSON Pointer to describe what to expect. There is some precedence with using JSON Pointer in Pushpin already, in the session feature (undocumented).

Example GRIP control messages below.

Respond to PING message with PONG message:

{"type": "auto-respond", "match-message-type": "ping", "message-type": "pong", "content": ""}

Respond to TEXT message {"type": "ping"} with TEXT message {"type": "pong"}:

{"type": "auto-respond", "match-content-ptr": "/type", "content-expect": "ping", "content": "{\"type\": \"pong\"}"}