Fixing confusing wss -> https case

This commit is contained in:
Joakim Erdfelt 2017-05-30 12:09:34 -07:00
parent c9c284f432
commit ae496051de
2 changed files with 11 additions and 11 deletions

View File

@ -31,7 +31,7 @@ public final class WSURI
* Convert to HTTP <code>http</code> or <code>https</code> scheme URIs.
* <p>
* Converting <code>ws</code> and <code>wss</code> URIs to their HTTP equivalent
*
*
* @param inputUri
* the input URI
* @return the HTTP scheme URI for the input URI.
@ -45,19 +45,19 @@ public final class WSURI
if ("http".equalsIgnoreCase(wsScheme) || "https".equalsIgnoreCase(wsScheme))
{
// leave alone
return new URI(inputUri.toString());
return inputUri;
}
if ("ws".equalsIgnoreCase(wsScheme))
{
// convert to http
return new URI("http"+inputUri.toString().substring(2));
return new URI("http" + inputUri.toString().substring(wsScheme.length()));
}
if ("wss".equalsIgnoreCase(wsScheme))
{
// convert to https
return new URI("http"+inputUri.toString().substring(2));
return new URI("https" + inputUri.toString().substring(wsScheme.length()));
}
throw new URISyntaxException(inputUri.toString(),"Unrecognized WebSocket scheme");
@ -67,7 +67,7 @@ public final class WSURI
* Convert to WebSocket <code>ws</code> or <code>wss</code> scheme URIs
* <p>
* Converting <code>http</code> and <code>https</code> URIs to their WebSocket equivalent
*
*
* @param inputUrl
* the input URI
* @return the WebSocket scheme URI for the input URI.
@ -83,7 +83,7 @@ public final class WSURI
* Convert to WebSocket <code>ws</code> or <code>wss</code> scheme URIs
* <p>
* Converting <code>http</code> and <code>https</code> URIs to their WebSocket equivalent
*
*
* @param inputUrl
* the input URI
* @param query
@ -103,10 +103,10 @@ public final class WSURI
/**
* Convert to WebSocket <code>ws</code> or <code>wss</code> scheme URIs
*
*
* <p>
* Converting <code>http</code> and <code>https</code> URIs to their WebSocket equivalent
*
*
* @param inputUri
* the input URI
* @return the WebSocket scheme URI for the input URI.
@ -126,13 +126,13 @@ public final class WSURI
if ("http".equalsIgnoreCase(httpScheme))
{
// convert to ws
return new URI("ws"+inputUri.toString().substring(4));
return new URI("ws" + inputUri.toString().substring(httpScheme.length()));
}
if ("https".equalsIgnoreCase(httpScheme))
{
// convert to wss
return new URI("wss"+inputUri.toString().substring(5));
return new URI("wss" + inputUri.toString().substring(httpScheme.length()));
}
throw new URISyntaxException(inputUri.toString(),"Unrecognized HTTP scheme");

View File

@ -44,7 +44,7 @@ public class WSURITest
{
assertURI(WSURI.toWebsocket(URI.create("https://localhost/")),URI.create("wss://localhost/"));
}
@Test
public void testHttpToHttp() throws URISyntaxException
{