diff --git a/extensions/Redis/packages.lock.json b/extensions/Redis/packages.lock.json new file mode 100644 index 0000000..18dc8e6 --- /dev/null +++ b/extensions/Redis/packages.lock.json @@ -0,0 +1,83 @@ +{ + "version": 1, + "dependencies": { + "net8.0": { + "Roslynator.Analyzers": { + "type": "Direct", + "requested": "[4.12.10, )", + "resolved": "4.12.10", + "contentHash": "Wecq3nfhTvnJPxX87hKbjMdX1xeCAMJf9rdBX3nQLTntQs9v0fFbUB2eQSSOArXMuFh7MxjLWaL4+b6XMi1NDA==" + }, + "StackExchange.Redis": { + "type": "Direct", + "requested": "[2.8.24, )", + "resolved": "2.8.24", + "contentHash": "GWllmsFAtLyhm4C47cOCipGxyEi1NQWTFUHXnJ8hiHOsK/bH3T5eLkWPVW+LRL6jDiB3g3izW3YEHgLuPoJSyA==", + "dependencies": { + "Microsoft.Extensions.Logging.Abstractions": "6.0.0", + "Pipelines.Sockets.Unofficial": "2.2.8" + } + }, + "Microsoft.Extensions.Logging.Abstractions": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/HggWBbTwy8TgebGSX5DBZ24ndhzi93sHUBDvP1IxbZD7FDokYzdAr6+vbWGjw2XAfR2EJ1sfKUotpjHnFWPxA==" + }, + "Pipelines.Sockets.Unofficial": { + "type": "Transitive", + "resolved": "2.2.8", + "contentHash": "zG2FApP5zxSx6OcdJQLbZDk2AVlN2BNQD6MorwIfV6gVj0RRxWPEp2LXAxqDGZqeNV1Zp0BNPcNaey/GXmTdvQ==", + "dependencies": { + "System.IO.Pipelines": "5.0.1" + } + }, + "System.IO.Pipelines": { + "type": "Transitive", + "resolved": "5.0.1", + "contentHash": "qEePWsaq9LoEEIqhbGe6D5J8c9IqQOUuTzzV6wn1POlfdLkJliZY3OlB0j0f17uMWlqZYjH7txj+2YbyrIA8Yg==" + }, + "simplecdn": { + "type": "Project" + } + }, + "net9.0": { + "Roslynator.Analyzers": { + "type": "Direct", + "requested": "[4.12.10, )", + "resolved": "4.12.10", + "contentHash": "Wecq3nfhTvnJPxX87hKbjMdX1xeCAMJf9rdBX3nQLTntQs9v0fFbUB2eQSSOArXMuFh7MxjLWaL4+b6XMi1NDA==" + }, + "StackExchange.Redis": { + "type": "Direct", + "requested": "[2.8.24, )", + "resolved": "2.8.24", + "contentHash": "GWllmsFAtLyhm4C47cOCipGxyEi1NQWTFUHXnJ8hiHOsK/bH3T5eLkWPVW+LRL6jDiB3g3izW3YEHgLuPoJSyA==", + "dependencies": { + "Microsoft.Extensions.Logging.Abstractions": "6.0.0", + "Pipelines.Sockets.Unofficial": "2.2.8" + } + }, + "Microsoft.Extensions.Logging.Abstractions": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/HggWBbTwy8TgebGSX5DBZ24ndhzi93sHUBDvP1IxbZD7FDokYzdAr6+vbWGjw2XAfR2EJ1sfKUotpjHnFWPxA==" + }, + "Pipelines.Sockets.Unofficial": { + "type": "Transitive", + "resolved": "2.2.8", + "contentHash": "zG2FApP5zxSx6OcdJQLbZDk2AVlN2BNQD6MorwIfV6gVj0RRxWPEp2LXAxqDGZqeNV1Zp0BNPcNaey/GXmTdvQ==", + "dependencies": { + "System.IO.Pipelines": "5.0.1" + } + }, + "System.IO.Pipelines": { + "type": "Transitive", + "resolved": "5.0.1", + "contentHash": "qEePWsaq9LoEEIqhbGe6D5J8c9IqQOUuTzzV6wn1POlfdLkJliZY3OlB0j0f17uMWlqZYjH7txj+2YbyrIA8Yg==" + }, + "simplecdn": { + "type": "Project" + } + } + } +} \ No newline at end of file diff --git a/src/core/Services/Compression/Implementations/CompressorBase.cs b/src/core/Services/Compression/Implementations/CompressorBase.cs index fd4e93b..c93689f 100644 --- a/src/core/Services/Compression/Implementations/CompressorBase.cs +++ b/src/core/Services/Compression/Implementations/CompressorBase.cs @@ -10,6 +10,13 @@ internal abstract class CompressorBase : ICompressor public bool Compress(Span data, out int newLength) { + if (data.Length < MinimumSize) + { + // the data is too small to be compressed + newLength = data.Length; + return false; + } + using var outputStream = new MemoryStream(); using (Stream compressorStream = Compress(outputStream)) { @@ -18,6 +25,8 @@ public bool Compress(Span data, out int newLength) if (outputStream.Length >= data.Length) { + // the compressed data is not smaller than the original data, + // so we return with the unchanged input data newLength = data.Length; return false; } diff --git a/src/standalone/AdditionalEndpoints.cs b/src/standalone/AdditionalEndpoints.cs index 5d79cb8..b04ce61 100644 --- a/src/standalone/AdditionalEndpoints.cs +++ b/src/standalone/AdditionalEndpoints.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http.Json; using Microsoft.Extensions.Options; using SimpleCDN.Endpoints; @@ -15,30 +15,29 @@ public static WebApplication MapEndpoints(this WebApplication app) { app.MapSimpleCDN(); #if DEBUG - if (app.Configuration.GetSection("Cache:Type").Get() == CacheType.InMemory) + // if the cache used is the in-memory implementation, add an endpoint to clear it + // as there is no other way to clear it without restarting the server, + // opposed to for example the Redis implementation which has the Redis CLI + app.MapGet("/" + GlobalConstants.SystemFilesRelativePath + "/server/cache/clear", (ICacheImplementationResolver cacheResolver) => { - // if the cache used is the in-memory implementation, add an endpoint to clear it - // as there is no other way to clear it without restarting the server, - // opposed to for example the Redis implementation which has the Redis CLI - app.MapGet("/" + GlobalConstants.SystemFilesRelativePath + "/server/cache/clear", (ICacheImplementationResolver cacheResolver) => - { - // TODO: currently, the browser makes a request to favicon.ico after the cache is cleared, - // which means there is a new cache entry created for the favicon.ico file. - // This is not a problem, but it would be nice to prevent this from happening. + // TODO: currently, the browser makes a request to favicon.ico after the cache is cleared, + // which means there is a new cache entry created for the favicon.ico file. + // This is not a problem, but it would be nice to prevent this from happening. - if (cacheResolver.Implementation is InMemoryCache imc) - { - imc.Clear(); - // force garbage collection to make sure all memory - // used by the cached files is properly released - GC.Collect(); + if (cacheResolver.Implementation is InMemoryCache imc) + { + imc.Clear(); + // force garbage collection to make sure all memory + // used by the cached files is properly released + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); - return Results.Ok(); - } + return Results.Ok(); + } + return Results.NotFound(); + }); - return Results.NotFound(); - }); - } #endif app.MapHealthChecks(); diff --git a/src/standalone/Program.cs b/src/standalone/Program.cs index 4cb131a..62fcb88 100644 --- a/src/standalone/Program.cs +++ b/src/standalone/Program.cs @@ -77,7 +77,7 @@ private static void DumpConfiguration(WebApplication app) Console.WriteLine(JsonSerializer.Serialize(inMemoryConfig.Value, jsonConfig)); Console.WriteLine("Redis Cache Configuration:"); Console.WriteLine(JsonSerializer.Serialize(redisConfig.Value, jsonConfig)); -#pragma warning restore IL2026, IL3050 +#pragma warning restore IL2026, IL3050, CA1869 // requires unreferenced code; reuse JsonSerializerOptions Console.WriteLine(); Console.Write("Selected cache implementation: "); diff --git a/tests/unit/packages.lock.json b/tests/unit/packages.lock.json new file mode 100644 index 0000000..ed66812 --- /dev/null +++ b/tests/unit/packages.lock.json @@ -0,0 +1,171 @@ +{ + "version": 1, + "dependencies": { + "net8.0": { + "coverlet.collector": { + "type": "Direct", + "requested": "[6.0.4, )", + "resolved": "6.0.4", + "contentHash": "lkhqpF8Pu2Y7IiN7OntbsTtdbpR1syMsm2F3IgX6ootA4ffRqWL5jF7XipHuZQTdVuWG/gVAAcf8mjk8Tz0xPg==" + }, + "Microsoft.NET.Test.Sdk": { + "type": "Direct", + "requested": "[17.12.0, )", + "resolved": "17.12.0", + "contentHash": "kt/PKBZ91rFCWxVIJZSgVLk+YR+4KxTuHf799ho8WNiK5ZQpJNAEZCAWX86vcKrs+DiYjiibpYKdGZP6+/N17w==", + "dependencies": { + "Microsoft.CodeCoverage": "17.12.0", + "Microsoft.TestPlatform.TestHost": "17.12.0" + } + }, + "NUnit": { + "type": "Direct", + "requested": "[4.3.2, )", + "resolved": "4.3.2", + "contentHash": "puVXayXNmEu7MFQSUswGmUjOy3M3baprMbkLl5PAutpeDoGTr+jPv33qAYsqxywi2wJCq8l/O3EhHoLulPE1iQ==" + }, + "NUnit.Analyzers": { + "type": "Direct", + "requested": "[4.6.0, )", + "resolved": "4.6.0", + "contentHash": "uK1TEViVBugOO6uDou1amu7CoNhrd2sEUFr/iaEmVfoeY8qq/zzWCCUZi97aCCSZmjnHKCCWKh3RucU27qPlKg==" + }, + "NUnit3TestAdapter": { + "type": "Direct", + "requested": "[4.6.0, )", + "resolved": "4.6.0", + "contentHash": "R7e1+a4vuV/YS+ItfL7f//rG+JBvVeVLX4mHzFEZo4W1qEKl8Zz27AqvQSAqo+BtIzUCo4aAJMYa56VXS4hudw==" + }, + "Roslynator.Analyzers": { + "type": "Direct", + "requested": "[4.12.10, )", + "resolved": "4.12.10", + "contentHash": "Wecq3nfhTvnJPxX87hKbjMdX1xeCAMJf9rdBX3nQLTntQs9v0fFbUB2eQSSOArXMuFh7MxjLWaL4+b6XMi1NDA==" + }, + "Microsoft.CodeCoverage": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "4svMznBd5JM21JIG2xZKGNanAHNXplxf/kQDFfLHXQ3OnpJkayRK/TjacFjA+EYmoyuNXHo/sOETEfcYtAzIrA==" + }, + "Microsoft.TestPlatform.ObjectModel": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "TDqkTKLfQuAaPcEb3pDDWnh7b3SyZF+/W9OZvWFp6eJCIiiYFdSB6taE2I6tWrFw5ywhzOb6sreoGJTI6m3rSQ==", + "dependencies": { + "System.Reflection.Metadata": "1.6.0" + } + }, + "Microsoft.TestPlatform.TestHost": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "MiPEJQNyADfwZ4pJNpQex+t9/jOClBGMiCiVVFuELCMSX2nmNfvUor3uFVxNNCg30uxDP8JDYfPnMXQzsfzYyg==", + "dependencies": { + "Microsoft.TestPlatform.ObjectModel": "17.12.0", + "Newtonsoft.Json": "13.0.1" + } + }, + "Newtonsoft.Json": { + "type": "Transitive", + "resolved": "13.0.1", + "contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==" + }, + "System.Reflection.Metadata": { + "type": "Transitive", + "resolved": "1.6.0", + "contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ==" + }, + "simplecdn": { + "type": "Project" + }, + "simplecdn.tests.mocks": { + "type": "Project", + "dependencies": { + "SimpleCDN": "[1.0.0, )" + } + } + }, + "net9.0": { + "coverlet.collector": { + "type": "Direct", + "requested": "[6.0.4, )", + "resolved": "6.0.4", + "contentHash": "lkhqpF8Pu2Y7IiN7OntbsTtdbpR1syMsm2F3IgX6ootA4ffRqWL5jF7XipHuZQTdVuWG/gVAAcf8mjk8Tz0xPg==" + }, + "Microsoft.NET.Test.Sdk": { + "type": "Direct", + "requested": "[17.12.0, )", + "resolved": "17.12.0", + "contentHash": "kt/PKBZ91rFCWxVIJZSgVLk+YR+4KxTuHf799ho8WNiK5ZQpJNAEZCAWX86vcKrs+DiYjiibpYKdGZP6+/N17w==", + "dependencies": { + "Microsoft.CodeCoverage": "17.12.0", + "Microsoft.TestPlatform.TestHost": "17.12.0" + } + }, + "NUnit": { + "type": "Direct", + "requested": "[4.3.2, )", + "resolved": "4.3.2", + "contentHash": "puVXayXNmEu7MFQSUswGmUjOy3M3baprMbkLl5PAutpeDoGTr+jPv33qAYsqxywi2wJCq8l/O3EhHoLulPE1iQ==" + }, + "NUnit.Analyzers": { + "type": "Direct", + "requested": "[4.6.0, )", + "resolved": "4.6.0", + "contentHash": "uK1TEViVBugOO6uDou1amu7CoNhrd2sEUFr/iaEmVfoeY8qq/zzWCCUZi97aCCSZmjnHKCCWKh3RucU27qPlKg==" + }, + "NUnit3TestAdapter": { + "type": "Direct", + "requested": "[4.6.0, )", + "resolved": "4.6.0", + "contentHash": "R7e1+a4vuV/YS+ItfL7f//rG+JBvVeVLX4mHzFEZo4W1qEKl8Zz27AqvQSAqo+BtIzUCo4aAJMYa56VXS4hudw==" + }, + "Roslynator.Analyzers": { + "type": "Direct", + "requested": "[4.12.10, )", + "resolved": "4.12.10", + "contentHash": "Wecq3nfhTvnJPxX87hKbjMdX1xeCAMJf9rdBX3nQLTntQs9v0fFbUB2eQSSOArXMuFh7MxjLWaL4+b6XMi1NDA==" + }, + "Microsoft.CodeCoverage": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "4svMznBd5JM21JIG2xZKGNanAHNXplxf/kQDFfLHXQ3OnpJkayRK/TjacFjA+EYmoyuNXHo/sOETEfcYtAzIrA==" + }, + "Microsoft.TestPlatform.ObjectModel": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "TDqkTKLfQuAaPcEb3pDDWnh7b3SyZF+/W9OZvWFp6eJCIiiYFdSB6taE2I6tWrFw5ywhzOb6sreoGJTI6m3rSQ==", + "dependencies": { + "System.Reflection.Metadata": "1.6.0" + } + }, + "Microsoft.TestPlatform.TestHost": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "MiPEJQNyADfwZ4pJNpQex+t9/jOClBGMiCiVVFuELCMSX2nmNfvUor3uFVxNNCg30uxDP8JDYfPnMXQzsfzYyg==", + "dependencies": { + "Microsoft.TestPlatform.ObjectModel": "17.12.0", + "Newtonsoft.Json": "13.0.1" + } + }, + "Newtonsoft.Json": { + "type": "Transitive", + "resolved": "13.0.1", + "contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==" + }, + "System.Reflection.Metadata": { + "type": "Transitive", + "resolved": "1.6.0", + "contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ==" + }, + "simplecdn": { + "type": "Project" + }, + "simplecdn.tests.mocks": { + "type": "Project", + "dependencies": { + "SimpleCDN": "[1.0.0, )" + } + } + } + } +} \ No newline at end of file