Replace StreamingResult with BinaryResult
The BinaryResult type allows RestApiViews to return an unknown content length with no gzip compression applied. This is the same as what a StreamingResult allowed, but uses less code by reusing the existing BinaryResult support. Change-Id: Ieefada279fc790ea9542dc386bcab1247eab4365
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.restapi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface StreamingResponse {
|
||||
public String getContentType();
|
||||
public void stream(OutputStream out) throws IOException;
|
||||
}
|
@@ -65,7 +65,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.extensions.restapi.StreamingResponse;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.httpd.WebSession;
|
||||
@@ -307,11 +306,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
}
|
||||
res.setStatus(status);
|
||||
|
||||
if (result instanceof StreamingResponse) {
|
||||
StreamingResponse r = (StreamingResponse) result;
|
||||
res.setContentType(r.getContentType());
|
||||
r.stream(res.getOutputStream());
|
||||
} else if (result != Response.none()) {
|
||||
if (result != Response.none()) {
|
||||
result = Response.unwrap(result);
|
||||
if (result instanceof BinaryResult) {
|
||||
replyBinaryResult(req, res, (BinaryResult) result);
|
||||
|
@@ -18,8 +18,8 @@ import com.google.common.base.Charsets;
|
||||
import com.google.gerrit.common.data.GarbageCollectionResult;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.StreamingResponse;
|
||||
import com.google.gerrit.server.git.GarbageCollection;
|
||||
import com.google.gerrit.server.project.GarbageCollect.Input;
|
||||
import com.google.inject.Inject;
|
||||
@@ -43,15 +43,10 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamingResponse apply(final ProjectResource rsrc, Input input) {
|
||||
return new StreamingResponse() {
|
||||
public BinaryResult apply(final ProjectResource rsrc, Input input) {
|
||||
return new BinaryResult() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/plain;charset=UTF-8";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stream(OutputStream out) throws IOException {
|
||||
public void writeTo(OutputStream out) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(
|
||||
new OutputStreamWriter(out, Charsets.UTF_8)) {
|
||||
@Override
|
||||
@@ -88,6 +83,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input> {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
};
|
||||
}.setContentType("text/plain; charset=UTF-8")
|
||||
.disableGzip();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user