GH-1064 Explicitly add content type to GCP response

Resolves #1064
This commit is contained in:
Oleg Zhurakousky
2023-08-30 15:46:39 +02:00
parent c1216da69c
commit 4cb7324a4e
2 changed files with 16 additions and 0 deletions

View File

@@ -121,6 +121,7 @@ public class FunctionInvoker implements HttpFunction, RawBackgroundFunction {
if (result != null) {
MessageHeaders headers = result.getHeaders();
httpResponse.setContentType(result.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString());
httpResponse.getWriter().write(new String(result.getPayload(), StandardCharsets.UTF_8));
for (Entry<String, Object> header : headers.entrySet()) {
Object values = header.getValue();

View File

@@ -89,6 +89,7 @@ public class FunctionInvokerHttpTests {
}
@Test
public void testJsonInputFunction() throws Exception {
@@ -103,8 +104,22 @@ public class FunctionInvokerHttpTests {
assertThat(writer.toString()).isEqualTo(gson.toJson(expectedOutput));
}
@Test
public void testWithKanji() throws Exception {
FunctionInvoker handler = new FunctionInvoker(JsonInputFunction.class);
String expectedOutput = "Thank you for sending the message: 森林";
IncomingRequest input = new IncomingRequest("森林");
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(gson.toJson(input))));
handler.service(request, response);
bufferedWriter.close();
assertThat(writer.toString()).isEqualTo(gson.toJson(expectedOutput));
}
@Test