Passing state while upgrading protocol #311

Closed
si14 opened this Issue Nov 6, 2012 · 10 comments

Projects

None yet

3 participants

@si14

Sometimes you need to verify some Request properties before upgrading to Websockets (it can be reasonable to fall back to plain HTML reply instead of WS upgrade, for example), and often it means extracting stuff from Request. If you also need this stuff in your Websocket code, duplication arises, because you can't pass anything from "plain" init to Websocket's init after upgrade. The proposal is to add an optional argument, allowing to pass the state to Websocket's init.

@dvv
dvv commented Nov 6, 2012

don't we have cowboy_req:set_meta(Key, Value, Req) for that?

@si14

It can be done with meta (I've overlooked inclusion of this feature, to be honest), but I'm not sure that this is the best way. Looks rather "hacky" to me.

@essen
Nine Nines member
@essen
Nine Nines member

So do you want to be able to pass just Req or Req, State? Req alone doesn't seem to make sense to me.

@essen
Nine Nines member

Will add a {upgrade, protocol, Protocol, Req, State}.

@dvv
dvv commented Dec 3, 2012

+1, as otherwise seen no means for Options passed to handlers in router rules to affect handler State.

@si14

Yeah, passing State will be great.

@essen
Nine Nines member

I can't allow {upgrade, protocol, Protocol, Req, State} actually. But I can allow overriding the Opts value with whatever you want (which would allow you to get your State there). So slightly different semantics, but same code and same result.

@essen
Nine Nines member

Done in 0851109fe1fc0b9f64c73a7f0eb1fd05d30c7401. Thanks!

@essen essen closed this Dec 3, 2012
@essen
Nine Nines member

Done in 5ef4a15 now. I forgot something unimportant.

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