mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
feat: support gzip encoding requests & use GZIPInputStream (#1104)
This commit is contained in:
parent
9071d5131a
commit
c774bf3311
@ -41,6 +41,7 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What this class provides:
|
* What this class provides:
|
||||||
@ -286,13 +287,19 @@ public class CordovaResourceApi {
|
|||||||
case URI_TYPE_HTTP:
|
case URI_TYPE_HTTP:
|
||||||
case URI_TYPE_HTTPS: {
|
case URI_TYPE_HTTPS: {
|
||||||
HttpURLConnection conn = (HttpURLConnection)new URL(uri.toString()).openConnection();
|
HttpURLConnection conn = (HttpURLConnection)new URL(uri.toString()).openConnection();
|
||||||
|
conn.setRequestProperty("Accept-Encoding", "gzip");
|
||||||
conn.setDoInput(true);
|
conn.setDoInput(true);
|
||||||
String mimeType = conn.getHeaderField("Content-Type");
|
String mimeType = conn.getHeaderField("Content-Type");
|
||||||
if (mimeType != null) {
|
if (mimeType != null) {
|
||||||
mimeType = mimeType.split(";")[0];
|
mimeType = mimeType.split(";")[0];
|
||||||
}
|
}
|
||||||
int length = conn.getContentLength();
|
int length = conn.getContentLength();
|
||||||
InputStream inputStream = conn.getInputStream();
|
InputStream inputStream;
|
||||||
|
if ("gzip".equals(conn.getContentEncoding())) {
|
||||||
|
inputStream = new GZIPInputStream(conn.getInputStream());
|
||||||
|
} else {
|
||||||
|
inputStream = conn.getInputStream();
|
||||||
|
}
|
||||||
return new OpenForReadResult(uri, inputStream, mimeType, length, null);
|
return new OpenForReadResult(uri, inputStream, mimeType, length, null);
|
||||||
}
|
}
|
||||||
case URI_TYPE_PLUGIN: {
|
case URI_TYPE_PLUGIN: {
|
||||||
|
Loading…
Reference in New Issue
Block a user