accept gzip content encoding

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@500 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-02-20 15:26:30 +00:00
parent 6a6698a7aa
commit e9f9e2055a

View file

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
/**
* @author Andreas Schildbach
@ -184,6 +185,7 @@ public final class ParserUtils
connection.setConnectTimeout(SCRAPE_CONNECT_TIMEOUT);
connection.setReadTimeout(SCRAPE_READ_TIMEOUT);
connection.addRequestProperty("User-Agent", SCRAPE_USER_AGENT);
connection.addRequestProperty("Accept-Encoding", "gzip");
// workaround to disable Vodafone compression
connection.addRequestProperty("Cache-Control", "no-cache");
@ -201,7 +203,13 @@ public final class ParserUtils
final int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
return connection.getInputStream();
final String contentEncoding = connection.getContentEncoding();
final InputStream is = connection.getInputStream();
if ("gzip".equalsIgnoreCase(contentEncoding))
return new GZIPInputStream(is);
return is;
}
else
{