#12220 closed enhancement (wontfix)
[Patch draft] Specify Content-Encoding for HTTP connections
Reported by: | simon04 | Owned by: | simon04 |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core | Version: | |
Keywords: | http compression urlconnection | Cc: |
Description
Currently, only the OsmServerReader
specifies the HTTP request header Accept-Encoding: gzip, deflate
to fetch the response in a compressed form (given the server supports it).
As a first improvement, Utils#openURLAndDecompress
could also send this header and uncompress the returned InputStream
:
-
src/org/openstreetmap/josm/tools/Utils.java
diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java index 53d45f5..6d6097d 100644
a b 54 54 import java.util.regex.Matcher; 55 55 import java.util.regex.Pattern; 56 56 import java.util.zip.GZIPInputStream; 57 import java.util.zip.Inflater; 58 import java.util.zip.InflaterInputStream; 57 59 import java.util.zip.ZipEntry; 58 60 import java.util.zip.ZipFile; 59 61 import java.util.zip.ZipInputStream; … … public static InputStream openURL(URL url) throws IOException { 800 802 */ 801 803 public static InputStream openURLAndDecompress(final URL url, final boolean decompress) throws IOException { 802 804 final URLConnection connection = setupURLConnection(url.openConnection()); 805 connection.setRequestProperty("Accept-Encoding", "gzip, deflate"); 803 806 final InputStream in = connection.getInputStream(); 804 807 if (decompress) { 805 808 switch (connection.getHeaderField("Content-Type")) { … … public static InputStream openURLAndDecompress(final URL url, final boolean deco 811 814 return getBZip2InputStream(in); 812 815 } 813 816 } 817 switch (connection.getContentEncoding()) { 818 case "gzip": 819 return getGZipInputStream(in); 820 case "deflate": 821 return new InflaterInputStream(in, new Inflater(true)); 822 } 814 823 return in; 815 824 } 816 825
In a next step, the 17 usages of Utils#openHttpConnection
could be adapted one-by-one to also make use of HTTP compression.
Attachments (0)
Change History (5)
comment:1 by , 9 years ago
Milestone: | → 15.12 |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Keywords: | http added; thtp removed |
---|
comment:4 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Close in favour of a broader solution in #12231.
comment:5 by , 9 years ago
Milestone: | 15.12 |
---|
Perhaps it also would make sense to use a more sophisticated HTTP client instead of keeping track of all those features ourselves. The one that came to my mind is https://github.com/google/google-http-java-client. Stripping it down to the "core packages"
com.google.api.client.http
,com.google.api.client.http.javanet
andcom.google.api.client.util
, it should be about 200kb as JAR …