karlseguin / websocket.zig

A websocket implementation for zig
MIT License
302 stars 28 forks source link

add afterInit hook to Handler #8

Closed ghost closed 1 year ago

ghost commented 1 year ago

I needed this for my use case because I wanted to send a message to a client immediately after it connects, but I found that sending it inside the init hook would cause the connection to fail somehow.

karlseguin commented 1 year ago

Thanks.

I made a follow up commit that moved the afterInit call a few lines above, before we init the buffer. If afterInit is going to fail via an error result, no point allocating that data.

karlseguin commented 1 year ago

As for why trying to write in init didn't work, it's because the websocket handshake doesn't get completed until after init returns. This is intentional, so that init can reject the request if it wants. So if you try to write in init, you're essentially sending the client an invalid reply to the handshake.