Skip to content

Update Uri.java #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/io/socket/client/Url.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class Url {
private static Pattern PATTERN_HTTPS = Pattern.compile("^(http|ws)s$");

private Url() {}

private String _host;

public static URL parse(String uri) throws URISyntaxException {
return parse(new URI(uri));
Expand Down Expand Up @@ -40,10 +42,15 @@ public static URL parse(URI uri) {
String userInfo = uri.getRawUserInfo();
String query = uri.getRawQuery();
String fragment = uri.getRawFragment();
// this is because of unsupported uri.getHost() on some of Samsung Devices such as S4.
_host = uri.getHost();
if (_host == null) {
_host = extractHostFromAuthorityPart(uri.getRawAuthority());
}
try {
return new URL(protocol + "://"
+ (userInfo != null ? userInfo + "@" : "")
+ uri.getHost()
+ _host
+ (port != -1 ? ":" + port : "")
+ path
+ (query != null ? "?" + query : "")
Expand All @@ -67,7 +74,11 @@ public static String extractId(URL url) {
port = 443;
}
}
return protocol + "://" + url.getHost() + ":" + port;
_host = uri.getHost();
if (_host == null) {
_host = extractHostFromAuthorityPart(uri.getRawAuthority());
}
return protocol + "://" + _host + ":" + port;
}

}