Skip to content

Commit 242d083

Browse files
authored
Change CustomHandler Type to enum (#6298)
1 parent c17b336 commit 242d083

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.Azure.WebJobs.Script.Workers.Http
5+
{
6+
public enum CustomHandlerType
7+
{
8+
Http = 0,
9+
None = 1
10+
}
11+
}

Diff for: src/WebJobs.Script/Workers/Http/Configuration/HttpWorkerOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Azure.WebJobs.Script.Workers.Http
55
{
66
public class HttpWorkerOptions
77
{
8-
public string Type { get; set; } = "http";
8+
public CustomHandlerType Type { get; set; }
99

1010
public HttpWorkerDescription Description { get; set; }
1111

Diff for: src/WebJobs.Script/Workers/Http/Configuration/HttpWorkerOptionsSetup.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public void Configure(HttpWorkerOptions options)
4747
{
4848
_metricsLogger.LogEvent(MetricEventNames.CustomHandlerConfiguration);
4949
ConfigureWorkerDescription(options, customHandlerSection);
50+
if (options.Type == CustomHandlerType.None)
51+
{
52+
// CustomHandlerType.None is only for maitaining backward compatibilty with httpWorker section.
53+
_logger.LogWarning($"CustomHandlerType {CustomHandlerType.None} is not supported. Defaulting to {CustomHandlerType.Http}.");
54+
options.Type = CustomHandlerType.Http;
55+
}
5056
return;
5157
}
5258

@@ -55,8 +61,8 @@ public void Configure(HttpWorkerOptions options)
5561
// TODO: Add aka.ms/link to new docs
5662
_logger.LogWarning($"Section {ConfigurationSectionNames.HttpWorker} will be deprecated. Please use {ConfigurationSectionNames.CustomHandler} section.");
5763
ConfigureWorkerDescription(options, httpWorkerSection);
58-
// Explicity set this empty to differentiate between customHandler and httpWorker options.
59-
options.Type = string.Empty;
64+
// Explicity set this to None to differentiate between customHandler and httpWorker options.
65+
options.Type = CustomHandlerType.None;
6066
}
6167
}
6268

Diff for: src/WebJobs.Script/Workers/Http/DefaultHttpWorkerService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Task InvokeAsync(ScriptInvocationContext scriptInvocationContext)
4141
if (scriptInvocationContext.FunctionMetadata.IsHttpInAndOutFunction())
4242
{
4343
// type is empty for httpWorker section. EnableForwardingHttpRequest is opt-in for custom handler section.
44-
if (string.IsNullOrEmpty(_httpWorkerOptions.Type) || _httpWorkerOptions.EnableForwardingHttpRequest)
44+
if (_httpWorkerOptions.Type == CustomHandlerType.None || _httpWorkerOptions.EnableForwardingHttpRequest)
4545
{
4646
return ProcessHttpInAndOutInvocationRequest(scriptInvocationContext);
4747
}
@@ -171,8 +171,8 @@ private HttpRequestMessage CreateAndGetHttpRequestMessage(string functionName, s
171171
private void AddRequestHeadersAndSetRequestUri(HttpRequestMessage httpRequestMessage, string functionName, string invocationId)
172172
{
173173
string pathValue = functionName;
174-
// _httpWorkerOptions.Type is populated only in customHandler section
175-
if (httpRequestMessage.RequestUri != null && !string.IsNullOrEmpty(_httpWorkerOptions.Type))
174+
// _httpWorkerOptions.Type is set to None only in HttpWorker section
175+
if (httpRequestMessage.RequestUri != null && _httpWorkerOptions.Type != CustomHandlerType.None)
176176
{
177177
pathValue = httpRequestMessage.RequestUri.AbsolutePath;
178178
}

Diff for: test/WebJobs.Script.Tests/HttpWorker/DefaultHttpWorkerServiceTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DefaultHttpWorkerServiceTests()
4343
_httpWorkerOptions = new HttpWorkerOptions()
4444
{
4545
Port = _defaultPort,
46-
Type = string.Empty
46+
Type = CustomHandlerType.None
4747
};
4848
}
4949

@@ -88,7 +88,7 @@ public async Task ProcessDefaultInvocationRequest_CustomHandler_EnableRequestFor
8888
var customHandlerOptions = new HttpWorkerOptions()
8989
{
9090
Port = _defaultPort,
91-
Type = "http"
91+
Type = CustomHandlerType.Http
9292
};
9393
handlerMock.Protected().Setup<Task<HttpResponseMessage>>("SendAsync",
9494
ItExpr.IsAny<HttpRequestMessage>(),
@@ -245,7 +245,6 @@ public async Task ProcessSimpleHttpTriggerInvocationRequest_CustomHandler_Enable
245245
var customHandlerOptions = new HttpWorkerOptions()
246246
{
247247
Port = _defaultPort,
248-
Type = "http",
249248
EnableForwardingHttpRequest = true
250249
};
251250
handlerMock.Protected().Setup<Task<HttpResponseMessage>>("SendAsync",

0 commit comments

Comments
 (0)