mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 00:08:49 +00:00
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:
parent
6a6698a7aa
commit
e9f9e2055a
1 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue