/**
* Dispatches the request without checking for the delayedRequestHandler()
* @param request
*/
public WOResponse dispatchRequestImmediately(WORequest request) {
WOResponse response;
if (ERXApplication.requestHandlingLog.isDebugEnabled()) {
ERXApplication.requestHandlingLog.debug(request);
}
try {
ERXApplication._startRequest();
ERXStats.initStatisticsIfNecessary();
checkMemory();
if (useComponentActionRedirection()) {
ERXComponentActionRedirector redirector = ERXComponentActionRedirector.redirectorForRequest(request);
if (redirector == null) {
response = super.dispatchRequest(request);
redirector = ERXComponentActionRedirector.currentRedirector();
if (redirector != null) {
response = redirector.redirectionResponse();
}
}
else {
response = redirector.originalResponse();
}
}
else {
response = super.dispatchRequest(request);
}
}
finally {
ERXStats.logStatisticsForOperation(statsLog, "key");
ERXApplication._endRequest();
}
if (requestHandlingLog.isDebugEnabled()) {
requestHandlingLog.debug("Returning, encoding: " + response.contentEncoding() + " response: " + response);
}
if (responseCompressionEnabled()) {
String contentType = response.headerForKey("content-type");
if (!"gzip".equals(response.headerForKey("content-encoding")) && (contentType != null) && (contentType.startsWith("text/") || responseCompressionTypes().containsObject(contentType))) {
String acceptEncoding = request.headerForKey("accept-encoding");
if ((acceptEncoding != null) && (acceptEncoding.toLowerCase().indexOf("gzip") != -1)) {
long start = System.currentTimeMillis();
long inputBytesLength;
InputStream contentInputStream = response.contentInputStream();
byte[] compressedData;
if (contentInputStream != null) {
inputBytesLength = response.contentInputStreamLength();
NSData compressedNSData = ERXCompressionUtilities.gzipInputStreamAsNSData(contentInputStream, (int)inputBytesLength);
//compressedData = compressedNSData._bytesNoCopy();
compressedData = compressedNSData.bytes();
response.setContentStream(null, 0, 0L);
}
else {
NSData input = response.content();
inputBytesLength = input.length();
compressedData = (inputBytesLength > 0) ? ERXCompressionUtilities.gzipByteArray(input._bytesNoCopy()) : null;
}
if ( inputBytesLength > 0 ) {
if (compressedData == null) {
// something went wrong
}
else {
response.setContent(new NSData(compressedData, new NSRange(0, compressedData.length), true));
response.setHeader(String.valueOf(compressedData.length), "content-length");
response.setHeader("gzip", "content-encoding");
if (log.isDebugEnabled()) {
log.debug("before: " + inputBytesLength + ", after " + compressedData.length + ", time: " + (System.currentTimeMillis() - start));
}
}
}