mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
EWS: implement gzip encoding on response
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1705 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
0f8153d8a5
commit
63fdfb111c
@ -1997,7 +1997,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
||||||
if (isGzipEncoded(method)) {
|
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
|
||||||
inputStream = (new GZIPInputStream(method.getResponseBodyAsStream()));
|
inputStream = (new GZIPInputStream(method.getResponseBodyAsStream()));
|
||||||
} else {
|
} else {
|
||||||
inputStream = method.getResponseBodyAsStream();
|
inputStream = method.getResponseBodyAsStream();
|
||||||
@ -2425,18 +2425,6 @@ public class DavExchangeSession extends 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// wrong hostname fix flag
|
// wrong hostname fix flag
|
||||||
protected boolean restoreHostName;
|
protected boolean restoreHostName;
|
||||||
|
|
||||||
@ -2568,7 +2556,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
||||||
if (isGzipEncoded(method)) {
|
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
|
||||||
inputStream = new GZIPInputStream(method.getResponseBodyAsStream());
|
inputStream = new GZIPInputStream(method.getResponseBodyAsStream());
|
||||||
} else {
|
} else {
|
||||||
inputStream = method.getResponseBodyAsStream();
|
inputStream = method.getResponseBodyAsStream();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package davmail.exchange.ews;
|
package davmail.exchange.ews;
|
||||||
|
|
||||||
import davmail.exchange.XMLStreamUtil;
|
import davmail.exchange.XMLStreamUtil;
|
||||||
|
import davmail.http.DavGatewayHttpClientFacade;
|
||||||
import davmail.util.StringUtil;
|
import davmail.util.StringUtil;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.Header;
|
||||||
@ -35,6 +36,7 @@ import javax.xml.stream.XMLStreamException;
|
|||||||
import javax.xml.stream.XMLStreamReader;
|
import javax.xml.stream.XMLStreamReader;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EWS SOAP method.
|
* EWS SOAP method.
|
||||||
@ -102,6 +104,7 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
this.itemType = itemType;
|
this.itemType = itemType;
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.responseCollectionName = responseCollectionName;
|
this.responseCollectionName = responseCollectionName;
|
||||||
|
setRequestHeader("Accept-Encoding", "gzip");
|
||||||
setRequestEntity(new RequestEntity() {
|
setRequestEntity(new RequestEntity() {
|
||||||
byte[] content;
|
byte[] content;
|
||||||
|
|
||||||
@ -988,7 +991,11 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
Header contentTypeHeader = getResponseHeader("Content-Type");
|
Header contentTypeHeader = getResponseHeader("Content-Type");
|
||||||
if (contentTypeHeader != null && "text/xml; charset=utf-8".equals(contentTypeHeader.getValue())) {
|
if (contentTypeHeader != null && "text/xml; charset=utf-8".equals(contentTypeHeader.getValue())) {
|
||||||
try {
|
try {
|
||||||
processResponseStream(getResponseBodyAsStream());
|
if (DavGatewayHttpClientFacade.isGzipEncoded(this)) {
|
||||||
|
processResponseStream(new GZIPInputStream(getResponseBodyAsStream()));
|
||||||
|
} else {
|
||||||
|
processResponseStream(getResponseBodyAsStream());
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("Error while parsing soap response: " + e, e);
|
LOGGER.error("Error while parsing soap response: " + e, e);
|
||||||
}
|
}
|
||||||
|
@ -663,6 +663,23 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the method response is gzip encoded
|
||||||
|
* @param method http method
|
||||||
|
* @return true if response is gzip encoded
|
||||||
|
*/
|
||||||
|
public static 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop HttpConnectionManager.
|
* Stop HttpConnectionManager.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user