Skip to content

Commit bc960b9

Browse files
committed
Fixing the service registration for IJobHostMiddlewarePipeline and updating the location for http configuration
1 parent 89945fb commit bc960b9

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

src/WebJobs.Script.WebHost/WebScriptHostBuilderExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP
7777
services.AddSingleton<DefaultScriptWebHookProvider>();
7878
services.TryAddSingleton<IScriptWebHookProvider>(p => p.GetService<DefaultScriptWebHookProvider>());
7979
services.TryAddSingleton<IWebHookProvider>(p => p.GetService<DefaultScriptWebHookProvider>());
80-
services.TryAddSingleton<IJobHostMiddlewarePipeline, DefaultMiddlewarePipeline>();
81-
services.TryAddSingleton<IJobHostHttpMiddleware, CustomHttpHeadersMiddleware>();
80+
services.TryAddEnumerable(ServiceDescriptor.Singleton<IJobHostMiddlewarePipeline, DefaultMiddlewarePipeline>());
81+
services.TryAddEnumerable(ServiceDescriptor.Singleton<IJobHostHttpMiddleware, CustomHttpHeadersMiddleware>());
8282
services.TryAddSingleton<IJobHostHttpMiddleware, HstsConfigurationMiddleware>();
8383

8484
// Make sure the registered IHostIdProvider is used

src/WebJobs.Script/Config/ConfigurationSectionNames.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public static class ConfigurationSectionNames
1313
public const string HostIdPath = WebHost + ":hostid";
1414
public const string ExtensionBundle = "extensionBundle";
1515
public const string ManagedDependency = "managedDependency";
16-
public const string Http = "http";
16+
public const string Extensions = "extensions";
17+
public const string Http = Extensions + ":http";
1718
public const string Hsts = Http + ":hsts";
1819
public const string CustomHttpHeaders = Http + ":customHeaders";
1920
}

test/WebJobs.Script.Tests/Configuration/CustomHttpHeadersOptionsSetupTests.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public CustomHttpHeadersOptionsSetupTests()
5050
}")]
5151
[InlineData(@"{
5252
'version': '2.0',
53-
'http': {
54-
'customHeaders': {
55-
'X-Content-Type-Options': 'nosniff'
53+
'extensions': {
54+
'http': {
55+
'customHeaders': {
56+
'X-Content-Type-Options': 'nosniff'
57+
}
5658
}
5759
}
5860
}")]
@@ -71,13 +73,15 @@ public void MissingOrValidCustomHttpHeadersConfig_DoesNotThrowException(string h
7173
public void ValidCustomHttpHeadersConfig_BindsToOptions()
7274
{
7375
string hostJsonContent = @"{
74-
'version': '2.0',
75-
'http': {
76-
'customHeaders': {
77-
'X-Content-Type-Options': 'nosniff'
78-
}
79-
}
80-
}";
76+
'version': '2.0',
77+
'extensions': {
78+
'http': {
79+
'customHeaders': {
80+
'X-Content-Type-Options': 'nosniff'
81+
}
82+
}
83+
}
84+
}";
8185
File.WriteAllText(_hostJsonFile, hostJsonContent);
8286
var configuration = BuildHostJsonConfiguration();
8387

test/WebJobs.Script.Tests/Configuration/HostHstsOptionsSetupTests.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ public HostHstsOptionsSetupTests()
5555
'version': '2.0',
5656
}")]
5757
[InlineData(@"{
58-
'version': '2.0',
59-
'http' : {
60-
'hsts' : {
61-
'isEnabled' : true
58+
'version': '2.0',
59+
'extensions': {
60+
'http': {
61+
'hsts': {
62+
'isEnabled': true,
63+
'maxAge': '10'
64+
}
6265
}
6366
}
6467
}")]
@@ -77,14 +80,16 @@ public void MissingOrValidHstsConfig_DoesNotThrowException(string hostJsonConten
7780
public void ValidHstsConfig_BindsToOptions()
7881
{
7982
string hostJsonContent = @"{
80-
'version': '2.0',
81-
'http': {
82-
'hsts': {
83-
'isEnabled': true,
84-
'maxAge': '10'
85-
}
86-
}
87-
}";
83+
'version': '2.0',
84+
'extensions': {
85+
'http': {
86+
'hsts': {
87+
'isEnabled': true,
88+
'maxAge': '10'
89+
}
90+
}
91+
}
92+
}";
8893
File.WriteAllText(_hostJsonFile, hostJsonContent);
8994
var configuration = BuildHostJsonConfiguration();
9095

0 commit comments

Comments
 (0)