NewLife/Stardust

去掉Url地址的默认端口
智能大石头 authored at 2022-09-21 21:53:31
929d71a
Tree
1 Parent(s) 353c567
Summary: 2 changed files with 34 additions and 1 deletions.
Added +31 -0
Modified +3 -1
Added +31 -0
diff --git a/ClientTest/AppServiceTests.cs b/ClientTest/AppServiceTests.cs
new file mode 100644
index 0000000..a9f60cc
--- /dev/null
+++ b/ClientTest/AppServiceTests.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace ClientTest;
+
+public class AppServiceTests
+{
+    [Fact]
+    public void Test1()
+    {
+        var str = "http://star.newlifex.com:80/";
+        var uri = new Uri(str);
+
+        var str2 = uri.ToString();
+        Assert.Equal("http://star.newlifex.com/", str2);
+    }
+
+    [Fact]
+    public void Test2()
+    {
+        var str = "https://star.newlifex.com:443/";
+        var uri = new Uri(str);
+
+        var str2 = uri.ToString();
+        Assert.Equal("https://star.newlifex.com/", str2);
+    }
+}
Modified +3 -1
diff --git a/Stardust.Server/Services/RegistryService.cs b/Stardust.Server/Services/RegistryService.cs
index 4fe08ba..b055835 100644
--- a/Stardust.Server/Services/RegistryService.cs
+++ b/Stardust.Server/Services/RegistryService.cs
@@ -170,7 +170,9 @@ namespace Stardust.Server.Services
                 {
                     foreach (var elm in addrs)
                     {
-                        if (!ds.Contains(elm)) ds.Add(elm);
+                        var url = elm;
+                        if (url.StartsWithIgnoreCase("http://", "https://")) url = new Uri(url).ToString().TrimEnd('/');
+                        if (!ds.Contains(url)) ds.Add(url);
                     }
                 }
             }