Skip to content

Commit 45322e8

Browse files
authored
Special case the 'RpcHttp.RawBody' field to always return the literal string (#210)
1 parent 60b4e1e commit 45322e8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Utility/TypeExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ private static HttpRequestContext ToHttpRequestContext (this RpcHttp rpcHttp)
5858

5959
if (rpcHttp.RawBody != null)
6060
{
61-
httpRequestContext.RawBody = rpcHttp.RawBody.ToObject();
61+
object rawBody = rpcHttp.RawBody.DataCase == TypedData.DataOneofCase.String
62+
? rpcHttp.RawBody.String
63+
: rpcHttp.RawBody.ToObject();
64+
65+
httpRequestContext.RawBody = rawBody;
6266
}
6367

6468
return httpRequestContext;

test/Unit/Utility/TypeExtensionsTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void TestTypedDataToObjectHttpRequestContextBodyData()
9090
var method = "Get";
9191
var url = "https://example.com";
9292
var data = "Hello World";
93+
var rawData = "{\"Foo\":\"Bar\"}";
9394

9495
var input = new TypedData
9596
{
@@ -103,7 +104,7 @@ public void TestTypedDataToObjectHttpRequestContextBodyData()
103104
},
104105
RawBody = new TypedData
105106
{
106-
String = data
107+
String = rawData
107108
}
108109
}
109110
};
@@ -121,7 +122,7 @@ public void TestTypedDataToObjectHttpRequestContextBodyData()
121122
Assert.Equal(httpRequestContext.Method, method);
122123
Assert.Equal(httpRequestContext.Url, url);
123124
Assert.Equal(httpRequestContext.Body, data);
124-
Assert.Equal(httpRequestContext.RawBody, data);
125+
Assert.Equal(httpRequestContext.RawBody, rawData);
125126
Assert.Empty(httpRequestContext.Headers);
126127
Assert.Empty(httpRequestContext.Params);
127128
Assert.Empty(httpRequestContext.Query);

0 commit comments

Comments
 (0)