Skip to content

Commit

Permalink
Merge pull request #664 from markusstoll/gzip
Browse files Browse the repository at this point in the history
content compression fixed
  • Loading branch information
darkv committed Jul 30, 2015
2 parents d83a486 + b98df89 commit 41b320a
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 = NSData.EmptyData;
}
}
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));
log.debug("before: " + inputBytesLength + ", after " + compressedData.length() + ", time: " + (System.currentTimeMillis() - start));
}
}
}
Expand Down

0 comments on commit 41b320a

Please sign in to comment.