vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

Add support for accesing headers to WebSocket handshake

Open wojtekerbetowski opened this issue 13 years ago • 3 comments

During the handshake headers are being sent to server (the same way like in HTTP).

The support should be probably added the through [Java/Groovy] getHeaders() method on WebSocket object.

Here is a sample code usage:

vertx.createHttpServer().websocketHandler { ws ->
  if(ws.headers["Authorization"] {
    ws.dataHandler { data -> ws.writeTextFrame(data.toString()) }
  } else {
    ws.reject()
  }
}.listen(8080)

wojtekerbetowski avatar Apr 01 '13 05:04 wojtekerbetowski

I'm also interested in this support. My primary driving force is accessing any and all HttpOnly cookies that the browser sends during the handshake. Because the cookies are HttpOnly there is no way for Javascript to do an attempt via websocket frames. (scripts don't have access to the httponly cookies).

coding2012 avatar Apr 03 '13 20:04 coding2012

Does it make sense to pass in the headers in the constructor, There is another issue for passing request params too.

DefaultWebSocket(VertxInternal vertx, String path, Map<String, String> headers, ServerConnection wsConn, Runnable connectRunnable) {

If this looks OK then I have this ready,

winash avatar Apr 20 '13 09:04 winash

Ok I just implemented this myself in the end. Thanks anyway.

purplefox avatar Apr 23 '13 11:04 purplefox