2

I am using socket.io with nodejs and an apache server over it. I am getting a code 200 as response, I know I must get 101.

WebSocket connection to 'wss://SITEABC.com/socket.io/?siteId=site1234567&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Invalid status line

The configuration on apache is the folowing:

RewriteCond %{HTTP:Upgrade} ^Websocket [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:1337/{REQUEST_URI} [P]

RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPass /socket.io/ http://localhost:1337/socket.io/

Node is running on port 1337

perseus
  • 1,322
  • 1
  • 16
  • 22

2 Answers2

5

I use springboot 2 + stomp. In my case ,the reason is in WebSocketConfig,must remove .withSockJS.

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").setAllowedOrigins("*")
                .addInterceptors(new HandshakeInterceptor())

                //--> important must remove,or 200 error.
                //.withSockJS()

                ;
    }
hatanooh
  • 3,891
  • 1
  • 14
  • 9
1

This means your requests are not being proxied to your WebSocket handler, but for some other route which returns a 200.

You should check your WebSocket handler.

Ishan Madhusanka
  • 641
  • 1
  • 11
  • 21
  • 1
    I have the same issue. Can you elaborate? – kiwicomb123 May 18 '18 at 01:41
  • In my case, the WebSocket request protocol for the requests were changed from ws:// to http:// which avoided requests being routed to the specific WebSocket handler on the backend – Ishan Madhusanka May 18 '18 at 03:26
  • I have a NodeJS server running on http://localhost:8082 which is meant to handle Websocket calls. It can't start sending ws:// etc calls until the handshake is complete. The handshake wont complete until a 101 status line is returned. its certainly receiving the requests because it falls back to Ajax when it can't complete the handshake. – kiwicomb123 May 18 '18 at 17:23
  • Falls back to Ajax..Yes. But it’s actually the socket.io library on client side which makes the Ajax call.. because it couldn’t complete the WebSocket handshake.. – Ishan Madhusanka May 18 '18 at 22:36
  • Yes I understand that part, sorry the way I phrased it made it sound like the server was doing Ajax calls. The problem was with the ProxyPass I was doing. I decided to pull the Node server out from behind the Apache server and to just have the app make calls to the Node server on a different port. The issue is fixed :) – kiwicomb123 May 18 '18 at 23:30
  • That’s Awesome! – Ishan Madhusanka May 18 '18 at 23:33