Skip to content

Commit ac130db

Browse files
authored
Add nullable header / query / params for HTTP (#326)
* Add nullable * make sure backwards compatible * Updated subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Tag: v1.3.9-protofile. Commit: eb8abdbe777a37d0a3f2ec4b32b5cde06ef72224
1 parent 7bb278f commit ac130db

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

azure-functions-language-worker-protobuf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Azure Functions Languge Worker Protobuf
1+
# Azure Functions Language Worker Protobuf
22

33
This repository contains the protobuf definition file which defines the gRPC service which is used between the [Azure Functions Host](https://github.com/Azure/azure-functions-host) and the Azure Functions language workers. This repo is shared across many repos in many languages (for each worker) by using git commands.
44

@@ -39,7 +39,7 @@ From within the Azure Functions language worker repo:
3939
## Releasing a Language Worker Protobuf version
4040

4141
1. Draft a release in the GitHub UI
42-
- Be sure to inculde details of the release
42+
- Be sure to include details of the release
4343
2. Create a release version, following semantic versioning guidelines ([semver.org](https://semver.org/))
4444
3. Tag the version with the pattern: `v<M>.<m>.<p>-protofile` (example: `v1.1.0-protofile`)
4545
3. Merge `dev` to `master`

azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ message WorkerInitRequest {
9696
// inform worker of supported categories and their levels
9797
// i.e. Worker = Verbose, Function.MyFunc = None
9898
map<string, RpcLog.Level> log_categories = 3;
99+
100+
// Full path of worker.config.json location
101+
string worker_directory = 4;
99102
}
100103

101104
// Worker responds with the result of initializing itself
@@ -481,4 +484,7 @@ message RpcHttp {
481484
TypedData rawBody = 17;
482485
repeated RpcClaimsIdentity identities = 18;
483486
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;
484490
}

src/WorkerChannel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export class WorkerChannel implements IWorkerChannel {
9292
RpcHttpTriggerMetadataRemoved: "true",
9393
RpcHttpBodyOnly: "true",
9494
IgnoreEmptyValuedRpcHttpHeaders: "true",
95-
WorkerStatus: "true"
95+
WorkerStatus: "true",
96+
UseNullableValueDictionaryForHttp: "true"
9697
};
9798
this._eventStream.write({
9899
requestId: requestId,

src/converters/RpcHttpConverters.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { AzureFunctionsRpcMessages as rpc } from '../../azure-functions-language-worker-protobuf/src/rpc';
1+
import {
2+
AzureFunctionsRpcMessages as rpc,
3+
INullableString
4+
} from '../../azure-functions-language-worker-protobuf/src/rpc';
25
import { HttpMethod, Cookie } from '../public/Interfaces';
36
import { RequestProperties } from '../http/Request';
47
import { Dict } from '../Context';
@@ -21,9 +24,9 @@ export function fromRpcHttp(rpcHttp: rpc.IRpcHttp): RequestProperties {
2124
method: <HttpMethod>rpcHttp.method,
2225
url: <string>rpcHttp.url,
2326
originalUrl: <string>rpcHttp.url,
24-
headers: <Dict<string>>rpcHttp.headers,
25-
query: <Dict<string>>rpcHttp.query,
26-
params: <Dict<string>>rpcHttp.params,
27+
headers: fromNullableMapping(rpcHttp.nullableHeaders, rpcHttp.headers),
28+
query: fromNullableMapping(rpcHttp.nullableQuery, rpcHttp.query),
29+
params: fromNullableMapping(rpcHttp.nullableParams, rpcHttp.params),
2730
body: fromTypedData(<rpc.ITypedData>rpcHttp.body),
2831
rawBody: fromRpcHttpBody(<rpc.ITypedData>rpcHttp.body),
2932
};
@@ -46,6 +49,18 @@ function fromRpcHttpBody(body: rpc.ITypedData) {
4649
}
4750
}
4851

52+
function fromNullableMapping(nullableMapping: { [k: string]: INullableString } | null | undefined, originalMapping?: { [k: string]: string } | null): Dict<string> {
53+
let converted = {};
54+
if (nullableMapping && Object.keys(nullableMapping).length > 0) {
55+
for (const key in nullableMapping) {
56+
converted[key] = nullableMapping[key].value || "";
57+
}
58+
} else if (originalMapping && Object.keys(originalMapping).length > 0) {
59+
converted = <Dict<string>>originalMapping;
60+
}
61+
return converted;
62+
}
63+
4964
/**
5065
* Converts the HTTP 'Response' object to an 'ITypedData' 'http' type to be sent through the RPC layer.
5166
* 'http' types are a special case from other 'ITypedData' types, which come from primitive types.

test/WorkerChannelTests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe('WorkerChannel', () => {
3131
'RpcHttpBodyOnly': "true",
3232
'RpcHttpTriggerMetadataRemoved': "true",
3333
'IgnoreEmptyValuedRpcHttpHeaders': "true",
34-
'WorkerStatus': "true"
34+
'WorkerStatus': "true",
35+
'UseNullableValueDictionaryForHttp': "true"
3536
},
3637
result: {
3738
status: rpc.StatusResult.Status.Success

0 commit comments

Comments
 (0)