Modify

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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  
    5454import java.util.regex.Matcher;
    5555import java.util.regex.Pattern;
    5656import java.util.zip.GZIPInputStream;
     57import java.util.zip.Inflater;
     58import java.util.zip.InflaterInputStream;
    5759import java.util.zip.ZipEntry;
    5860import java.util.zip.ZipFile;
    5961import java.util.zip.ZipInputStream;
    public static InputStream openURL(URL url) throws IOException {  
    800802     */
    801803    public static InputStream openURLAndDecompress(final URL url, final boolean decompress) throws IOException {
    802804        final URLConnection connection = setupURLConnection(url.openConnection());
     805        connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
    803806        final InputStream in = connection.getInputStream();
    804807        if (decompress) {
    805808            switch (connection.getHeaderField("Content-Type")) {
    public static InputStream openURLAndDecompress(final URL url, final boolean deco  
    811814                return getBZip2InputStream(in);
    812815            }
    813816        }
     817        switch (connection.getContentEncoding()) {
     818        case "gzip":
     819            return getGZipInputStream(in);
     820        case "deflate":
     821            return new InflaterInputStream(in, new Inflater(true));
     822        }
    814823        return in;
    815824    }
    816825

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 Don-vip, 8 years ago

Milestone: 15.12

comment:2 by simon04, 8 years ago

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 and com.google.api.client.util, it should be about 200kb as JAR …

comment:3 by Don-vip, 8 years ago

Keywords: http added; thtp removed

comment:4 by simon04, 8 years ago

Resolution: wontfix
Status: newclosed

Close in favour of a broader solution in #12231.

comment:5 by simon04, 8 years ago

Milestone: 15.12

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.