From 0d59f736cf478e49f8b6bf2b1d5b5f2316d617f5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 1 Dec 2012 10:33:18 -0800 Subject: [PATCH] Format h/help output as plain text not JSON The output produced when the client requested the h or help property from a JSON API is always produced from constant compiled into the server. Assume this safe to return to the client as text/plain content and avoid wrapping it into an HTML escaped JSON string. Change-Id: I942905924478cc3e297362f88fde7de007b4ebd2 --- .../com/google/gerrit/httpd/restapi/ParameterParser.java | 6 ++++-- .../com/google/gerrit/httpd/restapi/RestApiServlet.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/ParameterParser.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/ParameterParser.java index 1be1c03f19..7c41638474 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/ParameterParser.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/ParameterParser.java @@ -14,8 +14,8 @@ package com.google.gerrit.httpd.restapi; +import static com.google.gerrit.httpd.restapi.RestApiServlet.replyBinaryResult; import static com.google.gerrit.httpd.restapi.RestApiServlet.replyError; -import static com.google.gerrit.httpd.restapi.RestApiServlet.replyText; import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import com.google.common.annotations.VisibleForTesting; @@ -26,6 +26,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.gerrit.extensions.restapi.BadRequestException; +import com.google.gerrit.extensions.restapi.BinaryResult; import com.google.gerrit.server.util.Url; import com.google.gerrit.util.cli.CmdLineParser; import com.google.gson.JsonArray; @@ -78,7 +79,8 @@ class ParameterParser { msg.write('\n'); clp.printUsage(msg, null); msg.write('\n'); - replyText(req, res, msg.toString()); + replyBinaryResult(req, res, + BinaryResult.create(msg.toString()).setContentType("text/plain")); return false; } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index 8057346443..715300ac3b 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -494,7 +494,7 @@ public class RestApiServlet extends HttpServlet { } } - private static void replyBinaryResult( + static void replyBinaryResult( @Nullable HttpServletRequest req, HttpServletResponse res, BinaryResult bin) throws IOException {