Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ExecuteFunction.cs #13

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions csharp/ExecuteFunction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Copyright (C) Microsoft Corporation. All rights reserved.

namespace PlayFab.AzureFunctions
{
Expand Down Expand Up @@ -114,7 +114,7 @@ await httpClient.PostAsync(azureFunctionUri, functionRequestContent))

return new HttpResponseMessage
{
Content = new ByteArrayContent(CompressResponseBody(output, request)),
Content = CompressResponseBody(output, request),
StatusCode = HttpStatusCode.OK
};
}
Expand Down Expand Up @@ -383,7 +383,7 @@ private static async Task<string> DecompressHttpBody(HttpRequest request)
}
}

private static byte[] CompressResponseBody(object responseObject, HttpRequest request)
private static HttpContent CompressResponseBody(object responseObject, HttpRequest request)
{
string responseJson = PlayFabSimpleJson.SerializeObject(responseObject);
var responseBytes = Encoding.UTF8.GetBytes(responseJson);
Expand All @@ -394,7 +394,7 @@ private static byte[] CompressResponseBody(object responseObject, HttpRequest re
// If client doesn't specify accepted encodings, assume identity and respond decompressed
if (string.IsNullOrEmpty(encodingsString))
{
return responseBytes;
return new ByteArrayContent(responseBytes);
}

List<string> encodings = encodingsString.Replace(" ", String.Empty).Split(',').ToList();
Expand All @@ -403,7 +403,7 @@ private static byte[] CompressResponseBody(object responseObject, HttpRequest re
// If client accepts identity explicitly, respond decompressed
if (encodings.Contains("identity", StringComparer.OrdinalIgnoreCase))
{
return responseBytes;
return new ByteArrayContent(responseBytes);
}

// If client accepts gzip, compress
Expand All @@ -417,7 +417,9 @@ private static byte[] CompressResponseBody(object responseObject, HttpRequest re
}
responseBytes = stream.ToArray();
}
return responseBytes;
var content = new ByteArrayContent(responseBytes);
content.Headers.ContentEncoding.Add("gzip");
return content;
}

// If neither identity or gzip, throw error: we support gzip only right now
Expand Down