li4wang commented on code in PR #1966:
URL: https://github.com/apache/zookeeper/pull/1966#discussion_r1055081235
##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java:
##########
@@ -257,17 +263,84 @@ protected void doGet(
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
kwargs.put(entry.getKey(), entry.getValue()[0]);
}
+ final String authInfo =
request.getHeader(HttpHeader.AUTHORIZATION.asString());
// Run the command
- CommandResponse cmdResponse = Commands.runCommand(cmd, zkServer,
kwargs);
+ final CommandResponse cmdResponse = Commands.runCommand(cmd,
zkServer, kwargs, null, authInfo, request);
+ response.setStatus(cmdResponse.getStatusCode());
- // Format and print the output of the command
- CommandOutputter outputter = new JsonOutputter();
- response.setStatus(HttpServletResponse.SC_OK);
+ final Map<String, String> headers = cmdResponse.getHeaders();
+ for (final Map.Entry<String, String> header : headers.entrySet()) {
+ response.addHeader(header.getKey(), header.getValue());
+ }
+ final String clientIP =
IPAuthenticationProvider.getClientIPAddress(request);
+ if (cmdResponse.getInputStream() == null) {
+ // Format and print the output of the command
+ CommandOutputter outputter = new JsonOutputter(clientIP);
+ response.setContentType(outputter.getContentType());
+ outputter.output(cmdResponse, response.getWriter());
+ } else {
+ // Stream out the output of the command
+ CommandOutputter outputter = new StreamOutputter(clientIP);
+ response.setContentType(outputter.getContentType());
+ outputter.output(cmdResponse, response.getOutputStream());
+ }
+ }
+
+ /**
+ * Serves HTTP POST requests. It reads request payload as raw data.
+ * It's up to each command to process the payload accordingly.
+ * For example, RestoreCommand uses the payload InputStream directly
+ * to read snapshot data.
+ */
+ @Override
+ protected void doPost(final HttpServletRequest request,
+ final HttpServletResponse response) throws
ServletException, IOException {
+ final String cmdName = extractCommandNameFromURL(request,
response);
+ if (cmdName != null) {
+ final String authInfo =
request.getHeader(HttpHeader.AUTHORIZATION.asString());
+ final CommandResponse cmdResponse =
Commands.runCommand(cmdName, zkServer, null, request.getInputStream(),
authInfo, request);
Review Comment:
@sonatype-lift ignore
Although http header is user-supplied data, but we don't call out to OS
commands in the code base, so it can be ignored.
ProviderRegistry.addOrUpdateProvider(...) is an existing API before this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]