From 22402a860921a40d3e91adfb47784c171da9944e Mon Sep 17 00:00:00 2001 From: amoraller Date: Fri, 26 May 2023 00:24:59 +0300 Subject: [PATCH] [*] Disable Compression option (#121) --- .../BuilderExtensions.cs | 21 +++++++++++-------- src/EdjCase.JsonRpc.Router/Configuration.cs | 9 ++++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/EdjCase.JsonRpc.Router/BuilderExtensions.cs b/src/EdjCase.JsonRpc.Router/BuilderExtensions.cs index 21b2f71..ecea850 100644 --- a/src/EdjCase.JsonRpc.Router/BuilderExtensions.cs +++ b/src/EdjCase.JsonRpc.Router/BuilderExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using EdjCase.JsonRpc.Router; using EdjCase.JsonRpc.Router.Abstractions; using EdjCase.JsonRpc.Router.Defaults; @@ -43,16 +43,22 @@ public static IServiceCollection AddJsonRpc(this IServiceCollection serviceColle { throw new ArgumentNullException(nameof(serviceCollection)); } - + if (configuration == null) + { + configuration = new RpcServerConfiguration(); + } serviceCollection.AddSingleton(new RpcServicesMarker()); serviceCollection .TryAddScoped(); serviceCollection .TryAddScoped(); serviceCollection - .TryAddScoped(); - serviceCollection - .TryAddScoped(); + .TryAddScoped(); + if (configuration.UseCompression) + { + serviceCollection + .TryAddScoped(); + } serviceCollection .TryAddScoped(); serviceCollection @@ -69,10 +75,7 @@ public static IServiceCollection AddJsonRpc(this IServiceCollection serviceColle .TryAddSingleton(); serviceCollection.AddHttpContextAccessor(); - if (configuration == null) - { - configuration = new RpcServerConfiguration(); - } + return serviceCollection .AddSingleton(Options.Create(configuration)) .AddRouting() diff --git a/src/EdjCase.JsonRpc.Router/Configuration.cs b/src/EdjCase.JsonRpc.Router/Configuration.cs index 5e5a3d5..b8fc08b 100644 --- a/src/EdjCase.JsonRpc.Router/Configuration.cs +++ b/src/EdjCase.JsonRpc.Router/Configuration.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text.Json; using EdjCase.JsonRpc.Router.Abstractions; @@ -41,7 +41,12 @@ public class RpcServerConfiguration /// /// If specified the router will call the specified method when the invoker has finished. /// - public Action? OnInvokeEnd { get; set; } + public Action? OnInvokeEnd { get; set; } + + /// + /// If true will support use Gzip and Deflate compression + /// + public bool UseCompression { get; set; } = true; } public class ExceptionContext