Websocket with parameters

829 views
Skip to first unread message

Matthew Shaver

unread,
Aug 28, 2018, 6:09:55 PM8/28/18
to Gorilla web toolkit
I had a working test where I connect to a websocket but when I add a parameter I can no longer connect. 

This did not get an error:

  u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
  c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  if err != nil {
    t.Fatal("dial:", err)
  }

But this:

  u := url.URL{Scheme: "ws", Host: *addr, Path: "/?value=5"}
  c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  if err != nil {
    t.Fatal("dial:", err)
  }

Logs this error:

  dial: websocket: bad handshake

I had read that parameters are legal on a websocket but are they just not supported by Gorilla?

Matt S

unread,
Aug 28, 2018, 6:55:04 PM8/28/18
to goril...@googlegroups.com
Query parameters are valid in the RFC - https://tools.ietf.org/html/rfc6455#page-14

We also have some tests that include query strings.

My first pass is that your url.URL.Path field is invalid: "Path" is just the path. Use RawQuery directly, or:

params := url.Values{}
params.Set("key", "val")
u.RawQuery = params.Encode()

If you can open an issue on https://github.com/gorilla/websocket/issues if that doesn't work, it's a little easier for us to collaborate there.

--
You received this message because you are subscribed to the Google Groups "Gorilla web toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gorilla-web...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Shaver

unread,
Aug 28, 2018, 7:43:55 PM8/28/18
to Gorilla web toolkit
Thanks. That helped me verify adding the parameter. Turns out my real problem was in extracting it on the server side.
Reply all
Reply to author
Forward
0 new messages