Move base64 response encoding into BinaryResult
Make it easy for any RestApiView to return binary data within a base64 wrapper by marking a BinaryResult with base64() before it is given to RestApiServlet. The servlet will process the base64 wrapping before gzip encoding, which may save on transfer cost. Change-Id: I5ed7b8cb2b034b60654cc2574e627159b11a4f27
This commit is contained in:
@@ -61,6 +61,7 @@ public abstract class BinaryResult implements Closeable {
|
||||
private String characterEncoding;
|
||||
private long contentLength = -1;
|
||||
private boolean gzip = true;
|
||||
private boolean base64 = false;
|
||||
|
||||
/** @return the MIME type of the result, for HTTP clients. */
|
||||
public String getContentType() {
|
||||
@@ -110,6 +111,17 @@ public abstract class BinaryResult implements Closeable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** @return true if the result must be base64 encoded. */
|
||||
public boolean isBase64() {
|
||||
return base64;
|
||||
}
|
||||
|
||||
/** Wrap the binary data in base64 encoding. */
|
||||
public BinaryResult base64() {
|
||||
base64 = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write or copy the result onto the specified output stream.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user