From 4d4028d8d62c9cbb961a0d41864927d8cd1245fd Mon Sep 17 00:00:00 2001 From: Konrad Reiche Date: Sun, 5 Mar 2017 18:26:21 -0800 Subject: [PATCH] Inherit WebSocket protocol scheme in case of http and https Summary: **Motivation** Currently, when supplying a URL with protocol scheme `http` or `https` to the WebSocket module: ``` new WebSocket("http://10.0.2.2:8080") ``` it will result in the following error: ![Unable to get cookie from http://10.0.2.2:8080](https://cloud.githubusercontent.com/assets/661993/23584771/f3f9573e-011f-11e7-839e-eb100c8cb5d2.png) When a WebSocket URL with protocol scheme `http` or `https` is used the method [`getDefaultOrigin`](https://github.com/facebook/react-native/blob/be4afdde37ab6ff6ebe573821745887fd3edfb05/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java#L274-L301) will fail to substitute it and just returns a URL with empty protocol scheme leading to this opaque exception. Thus, in case of `http` or `https` it should just inherit the protocol scheme since the WebSocket is responsible for upgrading the HTTP/HTTPS connection to the WebSocket protocol. **Test plan** If anything this change makes the method more robust. The WebSock Closes https://github.com/facebook/react-native/pull/12713 Differential Revision: D4657738 Pulled By: ericvicenti fbshipit-source-id: 8835b539e94713355e063a2639b7293c764b084b --- .../com/facebook/react/modules/websocket/WebSocketModule.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java index 9634e63437e..d64a2c0193f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java @@ -281,6 +281,8 @@ public class WebSocketModule extends ReactContextBaseJavaModule { scheme += "https"; } else if (requestURI.getScheme().equals("ws")) { scheme += "http"; + } else if (requestURI.getScheme().equals("http") || requestURI.getScheme().equals("https")) { + scheme += requestURI.getScheme(); } if (requestURI.getPort() != -1) {