@@ -40,9 +40,18 @@ public async Task StartServer(string endpoint, CancellationToken cancellationTok
4040
4141 ParseWebSocketURL ( endpoint , out Uri uri ) ;
4242
43+ string scheme = uri . Scheme switch
44+ {
45+ "ws" => "http" ,
46+ "http" => "http" ,
47+ "wss" => "https" ,
48+ "https" => "https" ,
49+ _ => throw new ArgumentException ( string . Format ( "Unsupported Uri schema, \" {0}\" " , uri . Scheme ) )
50+ } ;
51+
4352 EmbeddedWebSocketServer . Options options = new ( )
4453 {
45- Scheme = uri . Scheme ,
54+ Scheme = scheme ,
4655 Host = uri . Host ,
4756 Port = uri . Port . ToString ( ) ,
4857 Path = uri . PathAndQuery ,
@@ -172,24 +181,24 @@ private static void ParseWebSocketURL(string endPoint, out Uri uri)
172181 uriToParse = endPoint ;
173182 }
174183
184+ string [ ] supportedSchemes = new string [ ] { "ws" , "wss" , "http" , "https" } ;
175185
176186 if ( ! string . IsNullOrEmpty ( uriToParse ) && Uri . TryCreate ( uriToParse , UriKind . Absolute , out uri ) )
177187 {
178- if ( uri . Scheme == "ws" )
179- {
180- uri = new UriBuilder ( uri ) { Scheme = "http" } . Uri ;
181- return ;
182- }
183- if ( uri . Scheme == "wss" )
188+ bool supported = false ;
189+ foreach ( string scheme in supportedSchemes )
184190 {
185- uri = new UriBuilder ( uri ) { Scheme = "https" } . Uri ;
186- return ;
191+ if ( string . Equals ( uri . Scheme , scheme , StringComparison . InvariantCultureIgnoreCase ) )
192+ {
193+ supported = true ;
194+ break ;
195+ }
187196 }
188- if ( uri . Scheme == "http" || uri . Scheme == "https" )
197+ if ( ! supported )
189198 {
190- return ;
199+ throw new ArgumentException ( string . Format ( "Unsupported Uri schema, \" {0} \" " , uri . Scheme ) ) ;
191200 }
192- throw new ArgumentException ( string . Format ( "Unsupported Uri schema, \" {0} \" " , uri . Scheme ) ) ;
201+ return ;
193202 }
194203 else
195204 {
0 commit comments