Gatling’s implementation of the open method obscures the “websocket upgrade request” (HTTP GET request to ws:// including special headers).
As a consequence, it isn’t logged.
Also, I cannot discern a means to add headers to this request (like a session cookie).
If this is (already fixed/won’t fix/not a bug/feature request) please let me know and I’ll file an issue on the github repo.
EDIT: I’ve configured ALL level logging on io.gatling.http; my understanding is that this should result in logging the HTTP GET request issued as part of the websocket upgrade, yet it does not.
I don’t really get it? Are you trying to add some custom headers during the handshake?
Is so, I’ll ask my favorite expert (Jean-François Arcand), but my first guess is that this is not allowed by the spec.
The relevant part is about adding additional headers, which is contained in the very last line.
### [1.2](http://tools.ietf.org/html/rfc6455#section-1.2). Protocol Overview
_This section is non-normative._
The protocol has two parts: a handshake and the data transfer.
The handshake from the client looks as follows:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
The handshake from the server looks as follows:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
The leading line from the client follows the Request-Line format.
The leading line from the server follows the Status-Line format. The
Request-Line and Status-Line productions are defined in [[RFC2616](http://tools.ietf.org/html/rfc2616)].
An unordered set of header fields comes after the leading line in
both cases. The meaning of these header fields is specified in
[Section 4](http://tools.ietf.org/html/rfc6455#section-4) of this document. Additional header fields may also be
present, such as cookies [[RFC6265](http://tools.ietf.org/html/rfc6265)].
OK, so we’re not talking about whatever header, but about Cookie.
Gatling uses AsyncHttpClient, and it covers what can be done with the Javascript API, i.e. most WebSocket client usage. And, correct me if I’m wrong, the Javascript API won’t let you set headers.
What the Javascript API lets you do if craft cookies and add them to the browser cookie jar.
So my first question is: where does your cookie come from? Does it come from the server, from a regular HTTP request that happened prior to connecting the WebSocket? Or is it crafted in Javascript, client side?
If the former, Gatling is supposed to automatically deal with this, and propagate existing cookies to the WebSocket. If it doesn’t work as expected, could you enable debug logging (root level, or Netty’s package) and provide more information, please?
If the latter, Gatling provides a way to manually add cookies to the cookie jar.
It must be in my usage of the DSL - I’ve tracked down where the session is consumed for the websocket open action - in my logs the http request and websocket upgrade request have different cookies (both valid, both different).
I checked all of the http requests before the websocket connection - it looks like the first request stores a session cookie, the subsequent requests neither store nor consume the previous key, and the websocket upgrade consumes the key from the first request.
In my test scenario I have several HTTP requests that are sent (get, post, etc) before the upgrade to websockets. It seems that the websocket upgrade will use the cookie from the FIRST http request made, and that (for whatever reason) session cookies are not maintained across the http requests. I’m not sure that gatling works as expected in this case.
resulted in the two HTTP requests acquiring different session tokens, and the first http request’s token being used for the websocket upgrade request.
I’ve subsequently removed the first request, and the issue is resolved, although I’d love to know why the token wasn’t persisting across those HTTP requests.