pygripcontrol icon indicating copy to clipboard operation
pygripcontrol copied to clipboard

Added automatic handling of PING events according to RFC 6455

Open Krolken opened this issue 9 months ago • 1 comments

Handle all PINGs automatically.

Pros: according to RFC that will include the content in the PONG.

Cons: no control over the PINGs in case you want to add some logic when a ping arrives.

In response to: https://github.com/fanout/django-grip/issues/21

Krolken avatar Mar 03 '25 15:03 Krolken

So I am not really sure what the desired functionality would be.

Either it is invisible to the user, but for example in my use case I would be interested when the last ping arrived or a larger change in the API is needed so that it is possible to handle the pings manually.

Krolken avatar Mar 03 '25 15:03 Krolken

This for bringing this up earlier. I made a fix in 5706cb6893bafe5929c9b290571d717b3df97ea3. Pings are still handled as the app processes messages, to ensure each event is handled in-order, however now any pings prior to the next message are handled when can_recv() is called. This should cover cases where a request contains only pings, or contains recv()-able messages followed by only pings. Also, the content is echoed in the pong.

If custom ping handling is needed, I'm open to adding a more low level API that maybe reads/writes WebSocketEvent objects. However, if all you need to do is inspect pings maybe checking in in_events is good enough.

jkarneges avatar Oct 24 '25 01:10 jkarneges