Skip to content

Commit 3d17497

Browse files
authored
Merge pull request #100 from JeringTech/fix-http-2-net-50
Fix http 2 for .Net 5.0
2 parents 3d3a0f8 + 90c98c4 commit 3d17497

20 files changed

+1671
-122
lines changed

Changelog.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ This project uses [semantic versioning](http://semver.org/spec/v2.0.0.html). Ref
33
*[Semantic Versioning in Practice](https://www.jering.tech/articles/semantic-versioning-in-practice)*
44
for an overview of semantic versioning.
55

6-
## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/6.0.0-beta.0...HEAD)
6+
## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/6.0.0-beta.1...HEAD)
7+
8+
## [6.0.0-beta.1](https://github.com/JeringTech/Javascript.NodeJS/compare/6.0.0-beta.0...6.0.0-beta.1) - Feb 22, 2021
9+
### Fixes
10+
- Fixed Http/2 for .Net 5.0. ([#100](https://github.com/JeringTech/Javascript.NodeJS/pull/100)).
711

812
## [6.0.0-beta.0](https://github.com/JeringTech/Javascript.NodeJS/compare/5.4.4...6.0.0-beta.0) - Feb 10, 2021
913
### Additions
1014
- Added NetCoreApp3.0 as a target.
11-
- Library uses HTTP/2 to communicate with Node.js when using NetCoreApp3.0 binaries.
15+
- Library uses HTTP/2 to communicate with Node.js when using NetCoreApp3.0 binaries. ([#97](https://github.com/JeringTech/Javascript.NodeJS/pull/97)).
1216
### Changes
1317
- **Breaking**: Simplified the surface area of `IHttpClientService`. Users can use DI to register a custom implementation of this service
1418
to customize their `HttpClient`.

License.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Licenses
2-
Jering.Javascript.NodeJS, copyright © 2018-2019 Jering. All rights reserved.
2+
Jering.Javascript.NodeJS, copyright © 2018-2021 Jering. All rights reserved.
33

44
## Source Code and Documentation Code-Examples
55
Source code and documentation code-examples are licensed under the following license:
@@ -186,4 +186,4 @@ Documentation (excluding code-examples), is licensed under a [CC BY 4.0](https:/
186186

187187
## Brand Assets
188188
Brand assets such as the Jering logo are not licensed under the above-mentioned licenses. You may not use these assets in
189-
a manner that might mislead users about the origin of your work. You may use these assets to refer to Jering.
189+
a manner that might mislead users about the origin of your work. You may use these assets to refer to Jering.

perf/NodeJS/ConcurrencyBenchmarks.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ConcurrencyBenchmarks
1313
{
1414
private const string DUMMY_WARMUP_MODULE = "module.exports = (callback) => callback()";
1515
private const string DUMMY_CONCURRENCY_MODULE_FILE = "dummyConcurrencyModule.js";
16-
private static readonly string _projectPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
16+
private static readonly string PROJECT_PATH = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
1717

1818
private ServiceProvider _serviceProvider;
1919
private INodeJSService _nodeJSService;
@@ -25,7 +25,7 @@ public void INodeJSService_Concurrency_MultiProcess_Setup()
2525
{
2626
var services = new ServiceCollection();
2727
services.AddNodeJS();
28-
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = _projectPath);
28+
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = PROJECT_PATH);
2929
services.Configure<OutOfProcessNodeJSServiceOptions>(options => options.Concurrency = Concurrency.MultiProcess);
3030
_serviceProvider = services.BuildServiceProvider();
3131
_nodeJSService = _serviceProvider.GetRequiredService<INodeJSService>();
@@ -57,7 +57,7 @@ public void INodeJSService_Concurrency_None_Setup()
5757
{
5858
var services = new ServiceCollection();
5959
services.AddNodeJS();
60-
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = _projectPath);
60+
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = PROJECT_PATH);
6161
_serviceProvider = services.BuildServiceProvider();
6262
_nodeJSService = _serviceProvider.GetRequiredService<INodeJSService>();
6363

@@ -86,7 +86,7 @@ public void INodeServices_Concurrency_Setup()
8686
var services = new ServiceCollection();
8787
services.AddNodeServices(options =>
8888
{
89-
options.ProjectPath = _projectPath;
89+
options.ProjectPath = PROJECT_PATH;
9090
options.WatchFileExtensions = null;
9191
});
9292
_serviceProvider = services.BuildServiceProvider();

perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>netcoreapp5.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<IsPackable>false</IsPackable>
77
<CodeAnalysisRuleSet>../../Jering.Javascript.NodeJS.ruleset</CodeAnalysisRuleSet>

perf/NodeJS/LatencyBenchmarks.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LatencyBenchmarks
1414
private const string DUMMY_WARMUP_MODULE = "module.exports = (callback) => callback()";
1515
private const string DUMMY_LATENCY_MODULE_FILE = "dummyLatencyModule.js";
1616
private const string DUMMY_MODULE_IDENTIFIER = "dummyLatencyModuleIdentifier";
17-
private static readonly string _projectPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
17+
private static readonly string PROJECT_PATH = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
1818

1919
private ServiceProvider _serviceProvider;
2020
private int _counter;
@@ -27,7 +27,7 @@ public void INodeJSService_Latency_InvokeFromFile_Setup()
2727
{
2828
var services = new ServiceCollection();
2929
services.AddNodeJS();
30-
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = _projectPath);
30+
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = PROJECT_PATH);
3131
_serviceProvider = services.BuildServiceProvider();
3232
_nodeJSService = _serviceProvider.GetRequiredService<INodeJSService>();
3333
_counter = 0;
@@ -50,7 +50,7 @@ public void INodeJSService_Latency_InvokeFromFile_GracefulShutdownEnabled_Setup(
5050
{
5151
var services = new ServiceCollection();
5252
services.AddNodeJS();
53-
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = _projectPath);
53+
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = PROJECT_PATH);
5454
services.Configure<OutOfProcessNodeJSServiceOptions>(options => options.EnableFileWatching = true);
5555
_serviceProvider = services.BuildServiceProvider();
5656
_nodeJSService = _serviceProvider.GetRequiredService<INodeJSService>();
@@ -87,7 +87,7 @@ public async Task<DummyResult> INodeJSService_Latency_InvokeFromCache()
8787

8888
private string DummyModuleFactory()
8989
{
90-
return File.ReadAllText(Path.Combine(_projectPath, DUMMY_LATENCY_MODULE_FILE));
90+
return File.ReadAllText(Path.Combine(PROJECT_PATH, DUMMY_LATENCY_MODULE_FILE));
9191
}
9292

9393
[Obsolete]
@@ -97,7 +97,7 @@ public void INodeServices_Latency_Setup()
9797
var services = new ServiceCollection();
9898
services.AddNodeServices(options =>
9999
{
100-
options.ProjectPath = _projectPath;
100+
options.ProjectPath = PROJECT_PATH;
101101
options.WatchFileExtensions = null;
102102
});
103103
_serviceProvider = services.BuildServiceProvider();

perf/NodeJS/RealWorkloadBenchmarks.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main(string[] args)
2222
Console.WriteLine(""Hello world {0}!"");
2323
}}
2424
}}";
25-
private static readonly string _projectPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
25+
private static readonly string PROJECT_PATH = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../../../Javascript"); // BenchmarkDotNet creates a project nested deep in bin
2626

2727
private int _counter;
2828
private ServiceProvider _serviceProvider;
@@ -35,7 +35,7 @@ public void INodeJSService_RealWorkload_Setup()
3535
{
3636
var services = new ServiceCollection();
3737
services.AddNodeJS();
38-
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = _projectPath); // Module loads prismjs from node_modules
38+
services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = PROJECT_PATH); // Module loads prismjs from node_modules
3939
services.Configure<OutOfProcessNodeJSServiceOptions>(options => options.Concurrency = Concurrency.MultiProcess);
4040
_serviceProvider = services.BuildServiceProvider();
4141
_nodeJSService = _serviceProvider.GetRequiredService<INodeJSService>();
@@ -66,7 +66,7 @@ public async Task<string[]> INodeJSService_RealWorkload()
6666

6767
private string DummyModuleFactory()
6868
{
69-
return File.ReadAllText(Path.Combine(_projectPath, DUMMY_REAL_WORKLOAD_MODULE_FILE));
69+
return File.ReadAllText(Path.Combine(PROJECT_PATH, DUMMY_REAL_WORKLOAD_MODULE_FILE));
7070
}
7171

7272
[Obsolete]
@@ -76,7 +76,7 @@ public void INodeServices_RealWorkload_Setup()
7676
var services = new ServiceCollection();
7777
services.AddNodeServices(options =>
7878
{
79-
options.ProjectPath = _projectPath;
79+
options.ProjectPath = PROJECT_PATH;
8080
options.WatchFileExtensions = null;
8181
});
8282
_serviceProvider = services.BuildServiceProvider();

perf/NodeJS/packages.lock.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": 1,
33
"dependencies": {
4-
".NETCoreApp,Version=v3.1": {
4+
".NETCoreApp,Version=v5.0": {
55
"BenchmarkDotNet": {
66
"type": "Direct",
77
"requested": "[0.12.0, )",
@@ -232,8 +232,7 @@
232232
"Microsoft.Extensions.DependencyInjection": "5.0.0",
233233
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0",
234234
"Microsoft.Extensions.Logging.Abstractions": "5.0.0",
235-
"Microsoft.Extensions.Options": "5.0.0",
236-
"System.Diagnostics.DiagnosticSource": "5.0.0"
235+
"Microsoft.Extensions.Options": "5.0.0"
237236
}
238237
},
239238
"Microsoft.Extensions.Logging.Abstractions": {
@@ -495,11 +494,6 @@
495494
"System.Runtime": "4.3.0"
496495
}
497496
},
498-
"System.Diagnostics.DiagnosticSource": {
499-
"type": "Transitive",
500-
"resolved": "5.0.0",
501-
"contentHash": "tCQTzPsGZh/A9LhhA6zrqCRV4hOHsK90/G7q3Khxmn6tnB1PuNU0cRaKANP2AWcF9bn0zsuOoZOSrHuJk6oNBA=="
502-
},
503497
"System.Diagnostics.FileVersionInfo": {
504498
"type": "Transitive",
505499
"resolved": "4.3.0",

src/NodeJS/Jering.Javascript.NodeJS.csproj

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netcoreapp3.0;net461</TargetFrameworks>
5-
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net461;net5.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard2.0;net5.0;netcoreapp3.1</TargetFrameworks>
66
<PackageId>Jering.Javascript.NodeJS</PackageId>
77
<Authors>JeremyTCD</Authors>
88
<Title>Invoke Javascript in NodeJS, from C#</Title>
@@ -21,8 +21,8 @@
2121
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2222
<PackageIconUrl>https://raw.githubusercontent.com/JeringTech/Javascript.NodeJS/master/nuget_icon.png</PackageIconUrl>
2323
<CodeAnalysisRuleSet>../../Jering.Javascript.NodeJS.ruleset</CodeAnalysisRuleSet>
24-
<HttpServerSourceName Condition="'$(TargetFramework)' == 'netcoreapp3.0'">Http20Server.js</HttpServerSourceName>
25-
<HttpServerSourceName Condition="'$(TargetFramework)' != 'netcoreapp3.0'">Http11Server.js</HttpServerSourceName>
24+
<HttpServerSourceName Condition="'$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0'">Http20Server.js</HttpServerSourceName>
25+
<HttpServerSourceName Condition="'$(TargetFramework)' != 'netcoreapp3.1' And '$(TargetFramework)' != 'net5.0'">Http11Server.js</HttpServerSourceName>
2626
<HttpServerBundleName>HttpServer.js</HttpServerBundleName>
2727
<!-- Exclude Javascript\bin and Javascript\node_modules from project - https://github.com/dotnet/cli/issues/7525 -->
2828
<DefaultItemExcludes>Javascript\bin\**;Javascript\node_modules\**;$(DefaultItemExcludes)</DefaultItemExcludes>
@@ -80,20 +80,14 @@
8080
</EmbeddedResource>
8181
</ItemGroup>
8282

83-
<!-- TODO one target per bundle or one target for all bundles? will have to generalize webpack.config if one target per bundle. -->
8483
<!--
8584
Notes on BeforeTargets: DispatchToInnerBuilds only runs if we're multi-targeting. PreBuildEvent runs before builds for each framework.
8685
If BeforeTargets contains only DispatchToInnerBuilds and we specify a framework when we call dotnet build, JavascriptBuild does not run.
8786
If BeforeTargets contains only PreBuildEvent and we multi-target, JavascriptBuild runs multiple times in parallel.
8887
So we must specify both. This way if we are multi-targeting, JavascriptBuild runs once, before DispatchToInnerBuilds after which inputs == outputs.
8988
If we aren't multi-targeting, JavascriptBuild runs before PreBuildEvent.
9089
-->
91-
<Target Name="JavascriptBuildNonWindows" BeforeTargets="PreBuildEvent" Inputs="@(JavascriptInputs)" Outputs="@(JavascriptOutputs)" Condition="'$(OS)' != 'Windows_NT'">
92-
<Yarn WorkingDirectory=".\Javascript" Command="run build --env.mode=$(Configuration) --env.entry=.\Servers\OutOfProcess\Http\Http11Server.ts" />
93-
<Yarn WorkingDirectory=".\Javascript" Command="run build --env.mode=$(Configuration) --env.entry=.\Servers\OutOfProcess\Http\Http20Server.ts" />
94-
</Target>
95-
96-
<Target Name="JavascriptBuildWindows" BeforeTargets="DispatchToInnerBuilds" Inputs="@(JavascriptInputs)" Outputs="@(JavascriptOutputs)" Condition="'$(OS)' == 'Windows_NT'">
90+
<Target Name="JavascriptBuildWindows" BeforeTargets="DispatchToInnerBuilds" Inputs="@(JavascriptInputs)" Outputs="@(JavascriptOutputs)">
9791
<Yarn WorkingDirectory=".\Javascript" Command="run build --env.mode=$(Configuration) --env.entry=.\Servers\OutOfProcess\Http\Http11Server.ts" />
9892
<Yarn WorkingDirectory=".\Javascript" Command="run build --env.mode=$(Configuration) --env.entry=.\Servers\OutOfProcess\Http\Http20Server.ts" />
9993
</Target>

src/NodeJS/NodeJSServiceCollectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IServiceCollection AddNodeJS(this IServiceCollection services)
4141

4242
internal static IHttpClientService IHttpClientServiceFactory(IServiceProvider serviceProvider)
4343
{
44-
#if NETCOREAPP3_0
44+
#if NETCOREAPP3_1
4545
// If not called, framework forces HTTP/1.1 so long as origin isn't https
4646
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
4747
#endif

src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSService.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
105105
using HttpContent httpContent = _httpContentFactory.Create(invocationRequest);
106106
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, _endpoint)
107107
{
108-
#if NETCOREAPP3_0
108+
#if NETCOREAPP3_1 || NET5_0
109109
Version = HttpVersion.Version20,
110+
#endif
111+
#if NET5_0
112+
VersionPolicy = HttpVersionPolicy.RequestVersionExact,
110113
#endif
111114
Content = httpContent
112115
};

src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/InvocationContent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class InvocationContent : HttpContent
1818
// Arbitrary boundary
1919
internal static readonly byte[] BOUNDARY_BYTES = Encoding.UTF8.GetBytes("--Uiw6+hXl3k+5ia0cUYGhjA==");
2020

21-
private static readonly MediaTypeHeaderValue _multipartContentType = new MediaTypeHeaderValue("multipart/mixed");
21+
private static readonly MediaTypeHeaderValue MULTIPART_CONTENT_TYPE = new MediaTypeHeaderValue("multipart/mixed");
2222
private readonly IJsonService _jsonService;
2323
private readonly InvocationRequest _invocationRequest;
2424

@@ -34,7 +34,7 @@ public InvocationContent(IJsonService jsonService, InvocationRequest invocationR
3434

3535
if (invocationRequest.ModuleSourceType == ModuleSourceType.Stream)
3636
{
37-
Headers.ContentType = _multipartContentType;
37+
Headers.ContentType = MULTIPART_CONTENT_TYPE;
3838
}
3939
}
4040

src/NodeJS/StaticNodeJSService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public static class StaticNodeJSService
1414
private static volatile ServiceProvider _serviceProvider;
1515
private static volatile IServiceCollection _services;
1616
private static volatile INodeJSService _nodeJSService;
17-
private static readonly object _createLock = new object();
17+
private static readonly object CREATE_LOCK = new object();
1818

1919
private static INodeJSService GetOrCreateNodeJSService()
2020
{
2121
if (_nodeJSService == null || _services != null)
2222
{
23-
lock (_createLock)
23+
lock (CREATE_LOCK)
2424
{
2525
if (_nodeJSService == null || _services != null)
2626
{

src/NodeJS/Utils/JsonService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Jering.Javascript.NodeJS
1111
/// </summary>
1212
public class JsonService : IJsonService
1313
{
14-
private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions
14+
private static readonly JsonSerializerOptions JSON_SERIALIZER_OPTIONS = new JsonSerializerOptions
1515
{
1616
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
1717

@@ -24,13 +24,13 @@ public class JsonService : IJsonService
2424
/// <inheritdoc />
2525
public ValueTask<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
2626
{
27-
return JsonSerializer.DeserializeAsync<T>(stream, _jsonSerializerOptions, cancellationToken);
27+
return JsonSerializer.DeserializeAsync<T>(stream, JSON_SERIALIZER_OPTIONS, cancellationToken);
2828
}
2929

3030
/// <inheritdoc />
3131
public Task SerializeAsync<T>(Stream stream, T value, CancellationToken cancellationToken = default)
3232
{
33-
return JsonSerializer.SerializeAsync(stream, value, _jsonSerializerOptions, cancellationToken);
33+
return JsonSerializer.SerializeAsync(stream, value, JSON_SERIALIZER_OPTIONS, cancellationToken);
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)