mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Add null checks for path in API endpoint handlers
Added null checks for the 'path' parameter in CanHandle methods across all API endpoint classes to prevent potential NullReferenceExceptions. Also made the _apis list in ResourceServer readonly and updated a comment for clarity.
This commit is contained in:
parent
741ade67c3
commit
c98fcfea10
|
|
@ -31,7 +31,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.Equals(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.Equals(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace WelsonJS.Launcher.ResourceTools
|
|||
|
||||
public bool CanHandle(HttpListenerContext context, string path)
|
||||
{
|
||||
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
return path != null && path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(HttpListenerContext context, string path)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace WelsonJS.Launcher
|
|||
private bool _isRunning;
|
||||
private string _prefix;
|
||||
private string _resourceName;
|
||||
private List<IApiEndpoint> _apis = new List<IApiEndpoint>();
|
||||
private readonly List<IApiEndpoint> _apis = new List<IApiEndpoint>();
|
||||
private BlobConfig _blobConfig;
|
||||
private readonly ILog _logger;
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ namespace WelsonJS.Launcher
|
|||
return;
|
||||
}
|
||||
|
||||
// Serve from a resource tool
|
||||
// Serve via API endpoints
|
||||
foreach (var api in _apis)
|
||||
{
|
||||
if (api.CanHandle(context, path))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user