Determine URL of client request from server side. Socket.io

半世苍凉 提交于 2019-12-23 04:34:05

问题


Ref: Socket.io Client Request Origin URL

Ref: Socket.io - How to get client URL request on server side?

How do you determine the URL of client request from server side? Client request may come from multiple domains.


回答1:


socket.io stores the request object from the original request that initiated the socket.io connection in socket.request.

On this request object is:

request.url
request.headers

The .url property will be the path of the URL (everything after the protocol, hostname and port).

The .headers property will contain any headers on the original request. In a cooperating browser, if the request is a cross origin request, then there will be an origin header that tells you what the domain was of the web page that the request was initiated from (it may also be present on a same-origin request too). This "origin" header will be accurate when coming from a trusted browser such as Chrome, IE, Safari, Firefox, etc..., but can easily be spoofed if coming from any other sort of agent (such as another server or script).



来源:https://stackoverflow.com/questions/29358328/determine-url-of-client-request-from-server-side-socket-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!