Skip to content

Commit

Permalink
netty: Use charset=utf-8, not encoding=utf-8 for error pages
Browse files Browse the repository at this point in the history
This has been wrong since the introduction of the code in df357cb.
Noticed as part of grpc/grpc-go#4491 . The error
text is generally ASCII, so this probably doesn't matter much.
  • Loading branch information
ejona86 committed Jul 19, 2021
1 parent b9becb5 commit a282019
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion netty/src/main/java/io/grpc/netty/NettyServerHandler.java
Expand Up @@ -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));
}
Expand Down
8 changes: 4 additions & 4 deletions netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit a282019

Please sign in to comment.