Skip to content

Commit 7c81c0d

Browse files
authored
Add nullable http proto (#6585)
1 parent ee89699 commit 7c81c0d

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/WebJobs.Script.Grpc/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto

+3
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,7 @@ message RpcHttp {
484484
TypedData rawBody = 17;
485485
repeated RpcClaimsIdentity identities = 18;
486486
repeated RpcHttpCookie cookies = 19;
487+
map<string,NullableString> nullable_headers = 20;
488+
map<string,NullableString> nullable_params = 21;
489+
map<string,NullableString> nullable_query = 22;
487490
}

src/WebJobs.Script/Workers/Rpc/MessageExtensions/RpcMessageConversionExtensions.cs

+33-7
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,51 @@ internal static async Task<TypedData> ToRpcHttp(this HttpRequest request, ILogge
128128
foreach (var pair in request.Query)
129129
{
130130
var value = pair.Value.ToString();
131-
if (!string.IsNullOrEmpty(value))
131+
if (ShouldUseNullableValueDictionary(capabilities))
132132
{
133-
http.Query.Add(pair.Key, value);
133+
http.NullableQuery.Add(pair.Key, new NullableString { Value = value });
134+
}
135+
else
136+
{
137+
if (!string.IsNullOrEmpty(value))
138+
{
139+
http.Query.Add(pair.Key, value);
140+
}
134141
}
135142
}
136143

137144
foreach (var pair in request.Headers)
138145
{
139-
if (ShouldIgnoreEmptyHeaderValues(capabilities) && string.IsNullOrEmpty(pair.Value.ToString()))
146+
if (ShouldUseNullableValueDictionary(capabilities))
140147
{
141-
continue;
148+
http.NullableHeaders.Add(pair.Key.ToLowerInvariant(), new NullableString { Value = pair.Value.ToString() });
142149
}
150+
else
151+
{
152+
if (ShouldIgnoreEmptyHeaderValues(capabilities) && string.IsNullOrEmpty(pair.Value.ToString()))
153+
{
154+
continue;
155+
}
143156

144-
http.Headers.Add(pair.Key.ToLowerInvariant(), pair.Value.ToString());
157+
http.Headers.Add(pair.Key.ToLowerInvariant(), pair.Value.ToString());
158+
}
145159
}
146160

147161
if (request.HttpContext.Items.TryGetValue(HttpExtensionConstants.AzureWebJobsHttpRouteDataKey, out object routeData))
148162
{
149163
Dictionary<string, object> parameters = (Dictionary<string, object>)routeData;
150164
foreach (var pair in parameters)
151165
{
152-
if (pair.Value != null)
166+
if (ShouldUseNullableValueDictionary(capabilities))
167+
{
168+
http.NullableParams.Add(pair.Key, new NullableString { Value = pair.Value.ToString() });
169+
}
170+
else
153171
{
154-
http.Params.Add(pair.Key, pair.Value.ToString());
172+
if (pair.Value != null)
173+
{
174+
http.Params.Add(pair.Key, pair.Value.ToString());
175+
}
155176
}
156177
}
157178
}
@@ -364,6 +385,11 @@ private static bool ShouldIgnoreEmptyHeaderValues(Capabilities capabilities)
364385
return !string.IsNullOrEmpty(capabilities.GetCapabilityState(RpcWorkerConstants.IgnoreEmptyValuedRpcHttpHeaders));
365386
}
366387

388+
private static bool ShouldUseNullableValueDictionary(Capabilities capabilities)
389+
{
390+
return !string.IsNullOrEmpty(capabilities.GetCapabilityState(RpcWorkerConstants.UseNullableValueDictionaryForHttp));
391+
}
392+
367393
public static BindingInfo ToBindingInfo(this BindingMetadata bindingMetadata)
368394
{
369395
BindingInfo bindingInfo = new BindingInfo

src/WebJobs.Script/Workers/Rpc/RpcWorkerConstants.cs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static class RpcWorkerConstants
3737
public const string RpcHttpTriggerMetadataRemoved = "RpcHttpTriggerMetadataRemoved";
3838
public const string IgnoreEmptyValuedRpcHttpHeaders = "IgnoreEmptyValuedRpcHttpHeaders";
3939
public const string WorkerStatus = "WorkerStatus";
40+
public const string UseNullableValueDictionaryForHttp = "UseNullableValueDictionaryForHttp";
4041

4142
// Host Capabilites
4243
public const string V2Compatable = "V2Compatable";

0 commit comments

Comments
 (0)