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`](be4afdde37/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
This commit is contained in:
Konrad Reiche 2017-03-05 18:26:21 -08:00 committed by Facebook Github Bot
parent c97c1e5516
commit 4d4028d8d6
1 changed files with 2 additions and 0 deletions

View File

@ -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) {