douhuo1738 2016-02-25 08:33
浏览 2259

在WebSocket中获取完整的URL

I'm using one of the golang samples to build a WebSocket server. According to the samples the struct Client access websocket.Conn here and websocket.Conn has a Request method returning *http.Request.

My idea is to subscribe the user to different channels depending on the subdomain they use to enter the app.

So is it possible to get the full URL the user hit when subscribed to the websocket? Using the sample code I thought ws.Conn.Request().URL.Host would give me something like ws://channel1.lvh.me:8080/sync but instead I'm getting the path: "/chat".

Is it possible to get the full URL the user used to connect to the websocket? Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douchuituo3032 2016-02-25 09:26
    关注

    func (*Conn) Request returns *http.Request

    func (ws *Conn) Request() *http.Request
    

    Checking the http.Request from the http package you will observe that it has a URL *url.URL type. This means that you should get the full url with:

    ws.Request().URL.Path
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能