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
This commit is contained in:
Shawn O. Pearce
2012-12-01 10:33:18 -08:00
parent 213d5ec4cd
commit 0d59f736cf
2 changed files with 5 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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 {