From a282019902031faf27e9ff2de1e3ae6ddb1f4954 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 19 Jul 2021 13:32:11 -0700 Subject: [PATCH] netty: Use charset=utf-8, not encoding=utf-8 for error pages This has been wrong since the introduction of the code in df357cb8. Noticed as part of https://github.com/grpc/grpc-go/pull/4491 . The error text is generally ASCII, so this probably doesn't matter much. --- netty/src/main/java/io/grpc/netty/NettyServerHandler.java | 2 +- .../test/java/io/grpc/netty/NettyServerHandlerTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/netty/src/main/java/io/grpc/netty/NettyServerHandler.java b/netty/src/main/java/io/grpc/netty/NettyServerHandler.java index 42b18695381..01ed7c0c373 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerHandler.java @@ -764,7 +764,7 @@ private void respondWithHttpError( Http2Headers headers = new DefaultHttp2Headers(true, serialized.length / 2) .status("" + code) - .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); + .set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8"); for (int i = 0; i < serialized.length; i += 2) { headers.add(new AsciiString(serialized[i], false), new AsciiString(serialized[i + 1], false)); } diff --git a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java index 6e1179bafa2..961f983d9cd 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java @@ -432,7 +432,7 @@ public void headersWithInvalidContentTypeShouldFail() throws Exception { .set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.INTERNAL.value())) .set(InternalStatus.MESSAGE_KEY.name(), "Content-Type 'application/bad' is not supported") .status("" + 415) - .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); + .set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8"); verifyWrite() .writeHeaders( @@ -457,7 +457,7 @@ public void headersWithInvalidMethodShouldFail() throws Exception { .set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.INTERNAL.value())) .set(InternalStatus.MESSAGE_KEY.name(), "Method 'FAKE' is not supported") .status("" + 405) - .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); + .set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8"); verifyWrite() .writeHeaders( @@ -481,7 +481,7 @@ public void headersWithMissingPathShouldFail() throws Exception { .set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.UNIMPLEMENTED.value())) .set(InternalStatus.MESSAGE_KEY.name(), "Expected path but is missing") .status("" + 404) - .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); + .set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8"); verifyWrite() .writeHeaders( @@ -506,7 +506,7 @@ public void headersWithInvalidPathShouldFail() throws Exception { .set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.UNIMPLEMENTED.value())) .set(InternalStatus.MESSAGE_KEY.name(), "Expected path to start with /: foo/bar") .status("" + 404) - .set(CONTENT_TYPE_HEADER, "text/plain; encoding=utf-8"); + .set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8"); verifyWrite() .writeHeaders(