Skip to content

Commit 992d489

Browse files
authored
Consume proto file repo and add enableContentNegotiation (#2696)
* Added subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Branch: dev. Commit: 894bebb * remove old files * updated nodejs worker nuget package and updated tests/behavior accordingly * fix tests * updates to tests * remove unused variable * update nodejs worker with grpc message siz
1 parent 8cf5398 commit 992d489

File tree

19 files changed

+702
-247
lines changed

19 files changed

+702
-247
lines changed

src/WebJobs.Script.Grpc/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Messages
2-
node_modules
2+
node_modules
3+
Proto

src/WebJobs.Script.Grpc/WebJobs.Script.Grpc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<Folder Include="Messages\DotNet\" />
3131
</ItemGroup>
3232

33-
<Target Name="GenerateProtoFiles" BeforeTargets="BeforeBuild" Inputs="Proto/FunctionRpc.proto" Outputs="Messages/DotNet/FunctionRpc.cs;Messages/DotNet/FunctionRpcGrpc.cs">
33+
<Target Name="GenerateProtoFiles" BeforeTargets="BeforeBuild" Inputs="Proto/src/proto/FunctionRpc.proto" Outputs="Messages/DotNet/FunctionRpc.cs;Messages/DotNet/FunctionRpcGrpc.cs">
3434
<Exec Command="./generate_protos.$(Ext)" />
3535
<ItemGroup>
3636
<Compile Include="**/*$(DefaultLanguageSourceExtension)" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(BaseIntermediateOutputPath)**;$(BaseOutputPath)**;@(Compile)" />

src/WebJobs.Script.Grpc/generate_protos.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ setlocal
3535
cd /d %~dp0
3636

3737
set NUGET_PATH=%UserProfile%\.nuget\packages\grpc.tools\1.4.1\tools\windows_x86
38-
set PROTO=.\Proto\FunctionRpc.proto
38+
set PROTO=.\Proto\src\proto\FunctionRpc.proto
3939
set MSGDIR=.\Messages
4040

4141
if exist %MSGDIR% rmdir /s /q %MSGDIR%
4242
mkdir %MSGDIR%
4343

4444
set OUTDIR=%MSGDIR%\DotNet
4545
mkdir %OUTDIR%
46-
%NUGET_PATH%\protoc.exe %PROTO% --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%NUGET_PATH%\grpc_csharp_plugin.exe --proto_path=.\Proto
46+
%NUGET_PATH%\protoc.exe %PROTO% --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%NUGET_PATH%\grpc_csharp_plugin.exe --proto_path=.\Proto\src\proto
4747

4848
@rem add pragma warning disable labels to generated files
4949

src/WebJobs.Script.Grpc/generate_protos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if [ -z "$NUGET_ROOT" ]; then
4848
else
4949
NUGET_PATH=$NUGET_ROOT/packages/grpc.tools/1.4.1/tools/$PLATFORM
5050
fi
51-
PROTO=./Proto/FunctionRpc.proto
51+
PROTO=./Proto/src/proto/FunctionRpc.proto
5252
MSGDIR=./Messages
5353

5454
if [ ! -d "$NUGET_PATH" ]; then
@@ -61,7 +61,7 @@ mkdir $MSGDIR
6161

6262
OUTDIR=$MSGDIR/DotNet
6363
mkdir $OUTDIR
64-
$NUGET_PATH/protoc $PROTO --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$NUGET_PATH/grpc_csharp_plugin --proto_path=./Proto
64+
$NUGET_PATH/protoc $PROTO --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$NUGET_PATH/grpc_csharp_plugin --proto_path=./Proto/src/proto
6565

6666
# add #pragma warning disable labels
6767

src/WebJobs.Script/Binding/Http/HttpBinding.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ internal static IActionResult CreateResult(HttpRequest request, object content)
8282

8383
int statusCode = StatusCodes.Status200OK;
8484
IDictionary<string, object> responseHeaders = null;
85-
bool isRawResponse = false;
85+
bool enableContentNegotiation = false;
8686
if (responseObject != null)
8787
{
88-
ParseResponseObject(responseObject, ref content, out responseHeaders, out statusCode, out isRawResponse);
88+
ParseResponseObject(responseObject, ref content, out responseHeaders, out statusCode, out enableContentNegotiation);
8989
}
9090

91-
return CreateResult(request, statusCode, content, responseHeaders, isRawResponse);
91+
return CreateResult(request, statusCode, content, responseHeaders, enableContentNegotiation);
9292
}
9393

94-
internal static void ParseResponseObject(IDictionary<string, object> responseObject, ref object content, out IDictionary<string, object> headers, out int statusCode, out bool isRawResponse)
94+
internal static void ParseResponseObject(IDictionary<string, object> responseObject, ref object content, out IDictionary<string, object> headers, out int statusCode, out bool enableContentNegotiation)
9595
{
9696
headers = null;
9797
statusCode = StatusCodes.Status200OK;
98-
isRawResponse = false;
98+
enableContentNegotiation = false;
9999

100100
// TODO: Improve this logic
101101
// Sniff the object to see if it looks like a response object
@@ -116,9 +116,9 @@ internal static void ParseResponseObject(IDictionary<string, object> responseObj
116116
statusCode = responseStatusCode.Value;
117117
}
118118

119-
if (responseObject.TryGetValue<bool>("isRaw", out bool isRawValue, ignoreCase: true))
119+
if (responseObject.TryGetValue<bool>("enableContentNegotiation", out bool enableContentNegotiationValue, ignoreCase: true))
120120
{
121-
isRawResponse = isRawValue;
121+
enableContentNegotiation = enableContentNegotiationValue;
122122
}
123123
}
124124
}
@@ -161,17 +161,17 @@ statusValue is long ||
161161
return false;
162162
}
163163

164-
private static IActionResult CreateResult(HttpRequest request, int statusCode, object content, IDictionary<string, object> headers, bool isRawResponse)
164+
private static IActionResult CreateResult(HttpRequest request, int statusCode, object content, IDictionary<string, object> headers, bool enableContentNegotiation)
165165
{
166-
if (isRawResponse)
166+
if (enableContentNegotiation)
167167
{
168168
// We only write the response through one of the formatters if
169-
// the function hasn't indicated that it wants to write the raw response
170-
return new RawScriptResult(statusCode, content) { Headers = headers };
169+
// the function has indicated that it wants to enable content negotiation
170+
return new ScriptObjectResult(content, headers) { StatusCode = statusCode };
171171
}
172172
else
173173
{
174-
return new ScriptObjectResult(content, headers) { StatusCode = statusCode };
174+
return new RawScriptResult(statusCode, content) { Headers = headers };
175175
}
176176
}
177177

src/WebJobs.Script/Rpc/MessageExtensions/Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static object ConvertFromHttpMessageToExpando(RpcHttp inputMessage)
2323
expando.query = inputMessage.Query as IDictionary<string, string>;
2424
expando.statusCode = inputMessage.StatusCode;
2525
expando.headers = inputMessage.Headers.ToDictionary(p => p.Key, p => (object)p.Value);
26-
expando.isRaw = inputMessage.IsRaw;
26+
expando.enableContentNegotiation = inputMessage.EnableContentNegotiation;
2727

2828
if (inputMessage.Body != null)
2929
{

src/WebJobs.Script/WebJobs.Script.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="1.1.0-beta2-10025">
2525
<PrivateAssets>None</PrivateAssets>
2626
</PackageReference>
27-
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta1-10026">
27+
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="1.0.0-beta1-10031">
2828
<PrivateAssets>None</PrivateAssets>
2929
</PackageReference>
3030
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta5" />

0 commit comments

Comments
 (0)