MCPcopy
hub / github.com/socketio/socket.io-client-java / parse

Method parse

src/main/java/io/socket/client/Url.java:26–64  ·  view source on GitHub ↗
(URI uri)

Source from the content-addressed store, hash-verified

24 }
25
26 public static ParsedURI parse(URI uri) {
27 String protocol = uri.getScheme();
28 if (protocol == null || !protocol.matches("^https?|wss?$")) {
29 protocol = "https";
30 }
31
32 int port = uri.getPort();
33 if (port == -1) {
34 if ("http".equals(protocol) || "ws".equals(protocol)) {
35 port = 80;
36 } else if ("https".equals(protocol) || "wss".equals(protocol)) {
37 port = 443;
38 }
39 }
40
41 String path = uri.getRawPath();
42 if (path == null || path.length() == 0) {
43 path = "/";
44 }
45
46 String userInfo = uri.getRawUserInfo();
47 String query = uri.getRawQuery();
48 String fragment = uri.getRawFragment();
49 String _host = uri.getHost();
50 if (_host == null) {
51 // might happen on some of Samsung Devices such as S4.
52 _host = extractHostFromAuthorityPart(uri.getRawAuthority());
53 }
54 URI completeUri = URI.create(protocol + "://"
55 + (userInfo != null ? userInfo + "@" : "")
56 + _host
57 + (port != -1 ? ":" + port : "")
58 + path
59 + (query != null ? "?" + query : "")
60 + (fragment != null ? "#" + fragment : ""));
61 String id = protocol + "://" + _host + ":" + port;
62
63 return new ParsedURI(completeUri, id);
64 }
65
66
67 private static String extractHostFromAuthorityPart(String authority)

Callers 3

parseMethod · 0.95
extractIdMethod · 0.95
socketMethod · 0.95

Calls 1

Tested by 2

parseMethod · 0.76
extractIdMethod · 0.76