use of org.apache.commons.httpclient.HttpVersion in project zm-mailbox by Zimbra.
the class SoapServlet method sendResponse.
private void sendResponse(HttpServletRequest req, HttpServletResponse resp, Element envelope) throws IOException {
SoapProtocol soapProto = SoapProtocol.determineProtocol(envelope);
int statusCode = soapProto.hasFault(envelope) ? HttpServletResponse.SC_INTERNAL_SERVER_ERROR : HttpServletResponse.SC_OK;
boolean chunkingEnabled = LC.soap_response_chunked_transfer_encoding_enabled.booleanValue();
if (chunkingEnabled) {
// disable chunking if proto < HTTP 1.1
String proto = req.getProtocol();
try {
HttpVersion httpVer = HttpVersion.parse(proto);
chunkingEnabled = !httpVer.lessEquals(HttpVersion.HTTP_1_0);
} catch (ProtocolException e) {
ZimbraLog.soap.warn("cannot parse http version in request: %s, http chunked transfer encoding disabled", proto, e);
chunkingEnabled = false;
}
}
// use jetty default if the LC key is not set
int responseBufferSize = soapResponseBufferSize();
if (responseBufferSize != -1)
resp.setBufferSize(responseBufferSize);
resp.setContentType(soapProto.getContentType());
resp.setStatus(statusCode);
resp.setHeader("Cache-Control", "no-store, no-cache");
if (chunkingEnabled) {
// Let jetty chunk the response if applicable.
ZimbraServletOutputStream out = new ZimbraServletOutputStream(resp.getOutputStream());
envelope.output(out);
out.flush();
} else {
// serialize the envelope to a byte array and send the response with Content-Length header.
byte[] soapBytes = envelope.toUTF8();
resp.setContentLength(soapBytes.length);
resp.getOutputStream().write(soapBytes);
resp.getOutputStream().flush();
}
envelope.destroy();
}
Aggregations