Эх сурвалжийг харах

add get scheme from X-Forwarded-Proto

Robert 10 сар өмнө
parent
commit
5667d8047b

+ 3 - 1
EVCB_OCPP.WSServer/Service/WsService/OcppWebsocketService.cs

@@ -168,6 +168,7 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
         if (context.RequestAborted.IsCancellationRequested) return false;
         if (string.IsNullOrEmpty(configVaule))
         {
+            logger.LogInformation("{id} {func} security profile not set", context.TraceIdentifier, nameof(ValidateHandshake));
             return true;
         }
 
@@ -180,6 +181,7 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
         if (session.ISOCPP20)
         {
             // 1.6 server only support change server  function
+            logger.LogInformation("{id} {func} {securityProfile} is ocpp20", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
             securityProfile = 0;
         }
 
@@ -199,7 +201,7 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
         {
             if (securityProfile == 2 && session.UriScheme == "ws")
             {
-                logger.LogInformation("{id} {func} {securityProfile} auth failed", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
+                logger.LogInformation("{id} {func} {securityProfile} connection unsecured", context.TraceIdentifier, nameof(ValidateHandshake), securityProfile);
                 context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                 return false;
             }

+ 11 - 3
EVCB_OCPP.WSServer/Service/WsService/WebsocketService.cs

@@ -115,11 +115,16 @@ public class WebsocketService<T> where T : WsSession
     private string GetScheme(HttpContext context)
     {
         string toReturn = string.Empty;
+        var rawScheme = string.Empty;
 
         if (context.Request.Headers.ContainsKey("x-original-host"))
         {
-            toReturn = new Uri(context.Request.Headers["x-original-host"]).Scheme;
-            return toReturn;
+            rawScheme = new Uri(context.Request.Headers["x-original-host"]).Scheme;
+        }
+        
+        if (context.Request.Headers.ContainsKey("X-Forwarded-Proto"))
+        {
+            rawScheme = context.Request.Headers["X-Forwarded-Proto"];
         }
 
         var origin = context.Request.Headers.Origin.FirstOrDefault();
@@ -132,7 +137,10 @@ public class WebsocketService<T> where T : WsSession
         {
         }
 
-        var rawScheme = context.Request.Scheme.ToLower();
+        if (string.IsNullOrEmpty(rawScheme))
+        {
+            rawScheme = context.Request.Scheme.ToLower();
+        }
         if (rawScheme == "http" ||
             rawScheme == "ws")
         {

+ 1 - 1
version.txt

@@ -1 +1 @@
-Docker_v1.1.25
+Docker_v1.1.26