Changeset 13036 in osm


Ignore:
Timestamp:
2009-01-08T09:40:26+01:00 (16 years ago)
Author:
stotz
Message:

HTTP user agent configurable

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java

    r11783 r13036  
    252252            url = new URL(tile.getUrl());
    253253            HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
     254            prepareHttpUrlConnection(urlConn);
    254255            urlConn.setRequestMethod("HEAD");
    255256            urlConn.setReadTimeout(30000); // 30 seconds read timeout
     
    267268            url = new URL(tile.getUrl());
    268269            HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
     270            prepareHttpUrlConnection(urlConn);
    269271            urlConn.setRequestMethod("HEAD");
    270272            urlConn.setReadTimeout(30000); // 30 seconds read timeout
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r11783 r13036  
    1919 */
    2020public class OsmTileLoader implements TileLoader {
     21
     22    /**
     23     * Holds the used user agent used for HTTP requests. If this field is
     24     * <code>null</code>, the default Java user agent is used.
     25     */
     26    public static String USER_AGENT = null;
     27    public static String ACCEPT = "text/html, image/png, image/jpeg, image/gif, */*";
    2128
    2229    protected TileLoaderListener listener;
     
    6673        url = new URL(tile.getUrl());
    6774        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    68         urlConn.setReadTimeout(30000); // 30 seconds read
    69         // timeout
     75        prepareHttpUrlConnection(urlConn);
     76        urlConn.setReadTimeout(30000); // 30 seconds read timeout
    7077        return urlConn;
     78    }
     79
     80    protected void prepareHttpUrlConnection(HttpURLConnection urlConn) {
     81        if (USER_AGENT != null)
     82            urlConn.setRequestProperty("User-agent", USER_AGENT);
     83        urlConn.setRequestProperty("Accept", ACCEPT);
    7184    }
    7285
Note: See TracChangeset for help on using the changeset viewer.