How To Send Request Header To Jetty WebSocket From JavaScript Client

倾然丶 夕夏残阳落幕 提交于 2020-01-06 14:12:44

问题


How To Send Request Header To Jetty WebSocket From JavaScript Client ?


What I am doing ?


At Client Side.

  1. Need To add service name and service version in request header at client side
  2. Send to server

At Server Side.

  1. Identify the service from the request header
  2. Using that create corresponding input translator (using GSON)
  3. Create service input using that translator
  4. Call the service.

I can use org.eclipse.jetty.websocket.api.annotations.WebSocket as to get service name and version at server side. But..... How can I set the header information at client side?

@OnWebSocketMessage
public void onText(Session session, String message) {
    if (session.isOpen()) {
        System.out.println(session.getUpgradeRequest().getHeader("service"));
        System.out.println(session.getUpgradeRequest().getHeader("version"));

        System.out.printf("Echoing back message [%s]%n", message);
        session.getRemote().sendString(message, null);
    }
}

Thanks for your support...


回答1:


Unfortunately, you can't. The standard WebSocket JavaScript API does not provide means to customize HTTP headers. See also this document at heroku dev center.



来源:https://stackoverflow.com/questions/29844804/how-to-send-request-header-to-jetty-websocket-from-javascript-client

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