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:
Namhyeon, Go 2026-01-31 23:21:53 +09:00
parent 741ade67c3
commit c98fcfea10
9 changed files with 10 additions and 10 deletions

View File

@ -31,7 +31,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -40,7 +40,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -38,7 +38,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -47,7 +47,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -44,7 +44,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)
{ {

View File

@ -34,7 +34,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -35,7 +35,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -29,7 +29,7 @@ namespace WelsonJS.Launcher.ResourceTools
public bool CanHandle(HttpListenerContext context, string path) 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) public async Task HandleAsync(HttpListenerContext context, string path)

View File

@ -31,7 +31,7 @@ namespace WelsonJS.Launcher
private bool _isRunning; private bool _isRunning;
private string _prefix; private string _prefix;
private string _resourceName; private string _resourceName;
private List<IApiEndpoint> _apis = new List<IApiEndpoint>(); private readonly List<IApiEndpoint> _apis = new List<IApiEndpoint>();
private BlobConfig _blobConfig; private BlobConfig _blobConfig;
private readonly ILog _logger; private readonly ILog _logger;
@ -151,7 +151,7 @@ namespace WelsonJS.Launcher
return; return;
} }
// Serve from a resource tool // Serve via API endpoints
foreach (var api in _apis) foreach (var api in _apis)
{ {
if (api.CanHandle(context, path)) if (api.CanHandle(context, path))