adonisjs/adonis-websocket

the slash (/) problem on socket path

mtamadon opened this issue · 0 comments

I have found a small bug on adonis Ws ,
If I add / on end of path in request , Ws server will returns "400 bad request" error and unfortunately most of client library add '/' at end of path.(Ex. most of android ws client libs and socket.io lib and ...) I know that adonis has official Js library but sometimes we need to connect to a Ws from android or ios app.

I found it using telnet let see an example:
Our websocket address is 127.0.0.1:3001/socket (path : 'socket')
and the request is:
GET /socket HTTP/1.1 Host: 127.0.0.1:3001 Connection: Upgrade Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Origin: http://localhost:63342 Sec-WebSocket-Version: 13 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,fa;q=0.8,ar;q=0.7 Cookie: _ga=GA1.1.2121443454.1510749600; csrftoken=r3Dc2FqBbBEbxNyreXRS3WT8C7QYGkYq8rVEbBL7xFOpS44upjvPeHFkuD5P12Dv Sec-WebSocket-Key: IzktWUEMLXAj5nr91pVXAg== Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

at response we get:

`HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 0ysRtfQC1JRuk7XCjVX1uUx9XwI=

?~?{"t":0,"d":{"connId":"cjj7udobh0000rirms57n3lds","serverInterval":30000,"serverAttempts":3,"clientInterval":25000,"clientAttempts":3}}
`

but if we add an slash ('/') at end of path:

GET /socket/ HTTP/1.1 Host: 127.0.0.1:3001 Connection: Upgrade Pragma: no-cache Cache-Control: no-cache Upgrade: websocket Origin: http://localhost:63342 Sec-WebSocket-Version: 13 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,fa;q=0.8,ar;q=0.7 Cookie: _ga=GA1.1.2121443454.1510749600; csrftoken=r3Dc2FqBbBEbxNyreXRS3WT8C7QYGkYq8rVEbBL7xFOpS44upjvPeHFkuD5P12Dv Sec-WebSocket-Key: IzktWUEMLXAj5nr91pVXAg== Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

the response will be:

`HTTP/1.1 400 Bad Request
Connection: close
Content-type: text/html
Content-Length: 11

Bad Request`

I think it is better to ignore slash . Currently I putted a slash at end of the path is config/socket.js but I think it is not a good solution.

Thanks for help,
Kind Regards