Ws: Missing upgradeReq property makes it impossible to determine request URL

Created on 19 Jun 2017  路  5Comments  路  Source: websockets/ws

Description

In version 3.0.0 the WebSocket.upgradeReq property has been removed. Unfortunately that means that now there's no simple way to determine on the server which URL the client originally requested. In version 2.3.1 you could do this simply using ws.upgradeReq.url where ws is the instance of the WebSocket class.

Reproducible in:

version: 3.0.0
Node.js version(s): any
OS version(s): any

Steps to reproduce:

N/A

Expected result:

N/A

Actual result:

N/A

Attachments:

N/A

Most helpful comment

You can save it when the connection event is emitted:

wss.on('connection', function connection(ws, req) {
  const url = req.url;
  // Do whatever you want with it.
  // You can even reattach it to the `ws` object if you need to.
});

All 5 comments

You can save it when the connection event is emitted:

wss.on('connection', function connection(ws, req) {
  const url = req.url;
  // Do whatever you want with it.
  // You can even reattach it to the `ws` object if you need to.
});

Great, I didn't see this possibility, many thanks for the hint!

ws.url=req.url

@Globik using ws.url will return undefined for me with version 3.2.1.

@cre8
Yes, it should be.
Please use req.url from second parameter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nodesocket picture nodesocket  路  4Comments

quesurifn picture quesurifn  路  3Comments

makc picture makc  路  4Comments

robertmylne picture robertmylne  路  3Comments

dcflow picture dcflow  路  4Comments