Skip to content

Commit

Permalink
content compression in ERXApplication never worked properly. NSData b…
Browse files Browse the repository at this point in the history
…ytesNoCopy gives you the complete buffer not only the valid content. So you get trash appended to your pages content.
  • Loading branch information
must21de committed Jul 30, 2015
1 parent d83a486 commit 49d4252
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2171,29 +2171,33 @@ public WOResponse dispatchRequestImmediately(WORequest request) {
long start = System.currentTimeMillis();
long inputBytesLength;
InputStream contentInputStream = response.contentInputStream();
byte[] compressedData;
NSData 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);
compressedData = ERXCompressionUtilities.gzipInputStreamAsNSData(contentInputStream, (int)inputBytesLength);
response.setContentStream(null, 0, 0);
}
else {
NSData input = response.content();
inputBytesLength = input.length();
compressedData = (inputBytesLength > 0) ? ERXCompressionUtilities.gzipByteArray(input._bytesNoCopy()) : null;
if(inputBytesLength > 0)
{
compressedData = ERXCompressionUtilities.gzipByteArrayAsNSData(input._bytesNoCopy(), 0, (int)inputBytesLength);
} else
{
compressedData = new NSData();
}
}
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.setContent(compressedData);
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));
System.out.println("before: " + inputBytesLength + ", after " + compressedData.length() + ", time: " + (System.currentTimeMillis() - start));
}
}
}
Expand Down

0 comments on commit 49d4252

Please sign in to comment.