1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

Allow Exchange server to use gzip compression

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1016 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-04-23 10:17:20 +00:00
parent 46ddc3a107
commit 7535496934

View File

@ -63,6 +63,7 @@ import java.net.UnknownHostException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.zip.GZIPInputStream;
/** /**
* Exchange session through Outlook Web Access (DAV) * Exchange session through Outlook Web Access (DAV)
@ -1649,15 +1650,32 @@ public class ExchangeSession {
} }
} }
protected boolean isGzipEncoded(HttpMethod method) {
Header[] contentEncodingHeaders = method.getResponseHeaders("Content-Encoding");
if (contentEncodingHeaders != null) {
for (Header header : contentEncodingHeaders) {
if ("gzip".equals(header.getValue())) {
return true;
}
}
}
return false;
}
protected void write(OutputStream os, String url, boolean doubleDot) throws IOException { protected void write(OutputStream os, String url, boolean doubleDot) throws IOException {
GetMethod method = new GetMethod(URIUtil.encodePath(url)); GetMethod method = new GetMethod(URIUtil.encodePath(url));
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
method.setRequestHeader("Translate", "f"); method.setRequestHeader("Translate", "f");
method.setRequestHeader("Accept-Encoding", "gzip");
BufferedReader reader = null; BufferedReader reader = null;
try { try {
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true); DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
if (isGzipEncoded(method)) {
reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(method.getResponseBodyAsStream())));
} else {
reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
}
OutputStreamWriter isoWriter = new OutputStreamWriter(os); OutputStreamWriter isoWriter = new OutputStreamWriter(os);
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {