Index: trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 9231)
+++ trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java	(revision 9232)
@@ -4,11 +4,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.net.HttpURLConnection;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Random;
 import java.util.Set;
@@ -27,4 +24,5 @@
 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
 import org.openstreetmap.josm.data.preferences.IntegerProperty;
+import org.openstreetmap.josm.tools.HttpClient;
 import org.openstreetmap.josm.tools.Utils;
 
@@ -311,32 +309,24 @@
             }
 
-            HttpURLConnection urlConn = getURLConnection(getUrl(), true);
+            final HttpClient request = getRequest("GET", true);
 
             if (isObjectLoadable()  &&
                     (now - attributes.getLastModification()) <= ABSOLUTE_EXPIRE_TIME_LIMIT) {
-                urlConn.setIfModifiedSince(attributes.getLastModification());
+                request.setIfModifiedSince(attributes.getLastModification());
             }
             if (isObjectLoadable() && attributes.getEtag() != null) {
-                urlConn.addRequestProperty("If-None-Match", attributes.getEtag());
-            }
-
-            log.log(Level.INFO, "GET {0} -> {1}", new Object[]{getUrl(), urlConn.getResponseCode()});
-
-            // follow redirects
-            for (int i = 0; i < 5; i++) {
-                if (urlConn.getResponseCode() == 302) {
-                    urlConn = getURLConnection(new URL(urlConn.getHeaderField("Location")), true);
-                } else {
-                    break;
-                }
-            }
+                request.setHeader("If-None-Match", attributes.getEtag());
+            }
+
+            final HttpClient.Response urlConn = request.connect();
+
             if (urlConn.getResponseCode() == 304) {
                 // If isModifiedSince or If-None-Match has been set
                 // and the server answers with a HTTP 304 = "Not Modified"
-                log.log(Level.FINE, "JCS - IfModifiedSince/Etag test: local version is up to date: {0}", getUrl());
+                log.log(Level.FINE, "JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl());
                 return true;
-            } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 resposne code
+            } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 response code
                     && (
-                            (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getRequestProperty("ETag"))) ||
+                            (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getHeaderField("ETag"))) ||
                             attributes.getLastModification() == urlConn.getLastModified())
                     ) {
@@ -344,5 +334,5 @@
                 // for further requests - use HEAD
                 String serverKey = getServerKey();
-                log.log(Level.INFO, "JCS - Host: {0} found not to return 304 codes for If-Modifed-Since or If-None-Match headers",
+                log.log(Level.INFO, "JCS - Host: {0} found not to return 304 codes for If-Modified-Since or If-None-Match headers",
                         serverKey);
                 useHead.put(serverKey, Boolean.TRUE);
@@ -361,5 +351,5 @@
                 byte[] raw;
                 if (urlConn.getResponseCode() == 200) {
-                    raw = Utils.readBytesFromStream(urlConn.getInputStream());
+                    raw = Utils.readBytesFromStream(urlConn.getContent());
                 } else {
                     raw = new byte[]{};
@@ -434,5 +424,5 @@
     protected abstract V createCacheEntry(byte[] content);
 
-    protected CacheEntryAttributes parseHeaders(URLConnection urlConn) {
+    protected CacheEntryAttributes parseHeaders(HttpClient.Response urlConn) {
         CacheEntryAttributes ret = new CacheEntryAttributes();
 
@@ -461,26 +451,18 @@
         ret.setEtag(urlConn.getHeaderField("ETag"));
 
-        if (Main.isDebugEnabled()) {
-            for (Entry<String, List<String>> header: urlConn.getHeaderFields().entrySet()) {
-                log.log(Level.FINE, "Response header - {0}: {1}", new Object[]{header.getKey(), header.getValue()});
-            }
-        }
-
         return ret;
     }
 
-    private HttpURLConnection getURLConnection(URL url, boolean noCache) throws IOException {
-        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
-        urlConn.setRequestProperty("Accept", "text/html, image/png, image/jpeg, image/gif, */*");
+    private HttpClient getRequest(String requestMethod, boolean noCache) throws IOException {
+        final HttpClient urlConn = HttpClient.create(getUrl(), requestMethod);
+        urlConn.setAccept("text/html, image/png, image/jpeg, image/gif, */*");
         urlConn.setReadTimeout(readTimeout); // 30 seconds read timeout
         urlConn.setConnectTimeout(connectTimeout);
         if (headers != null) {
-            for (Map.Entry<String, String> e: headers.entrySet()) {
-                urlConn.setRequestProperty(e.getKey(), e.getValue());
-            }
+            urlConn.setHeaders(headers);
         }
 
         if (force || noCache) {
-            urlConn.setUseCaches(false);
+            urlConn.useCache(false);
         }
         return urlConn;
@@ -488,15 +470,7 @@
 
     private boolean isCacheValidUsingHead() throws IOException {
-        HttpURLConnection urlConn = getURLConnection(getUrl(), false);
-        urlConn.setRequestMethod("HEAD");
-        for (int i = 0; i < 5; i++) {
-            if (urlConn.getResponseCode() == 302) {
-                urlConn = getURLConnection(new URL(urlConn.getHeaderField("Location")), false);
-            } else {
-                break;
-            }
-        }
+        final HttpClient.Response urlConn = getRequest("HEAD", false).connect();
         long lastModified = urlConn.getLastModified();
-        return (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getRequestProperty("ETag"))) ||
+        return (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getHeaderField("ETag"))) ||
                 (lastModified != 0 && lastModified <= attributes.getLastModification());
     }
Index: trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java	(revision 9231)
+++ trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java	(revision 9232)
@@ -7,5 +7,4 @@
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.HashSet;
 import java.util.List;
@@ -31,4 +30,5 @@
 import org.openstreetmap.josm.data.cache.ICachedLoaderListener;
 import org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob;
+import org.openstreetmap.josm.tools.HttpClient;
 
 /**
@@ -240,5 +240,5 @@
 
     @Override
-    protected CacheEntryAttributes parseHeaders(URLConnection urlConn) {
+    protected CacheEntryAttributes parseHeaders(HttpClient.Response urlConn) {
         CacheEntryAttributes ret = super.parseHeaders(urlConn);
         // keep the expiration time between MINIMUM_EXPIRES and MAXIMUM_EXPIRES, so we will cache the tiles
Index: trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java	(revision 9231)
+++ trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java	(revision 9232)
@@ -200,5 +200,5 @@
 
     protected SessionId extractOsmSession() {
-        List<String> setCookies = connection.getHeaderFields("Set-Cookie");
+        List<String> setCookies = connection.getHeaderFields().get("Set-Cookie");
         if (setCookies == null)
             // no cookies set
Index: trunk/src/org/openstreetmap/josm/tools/HttpClient.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/HttpClient.java	(revision 9231)
+++ trunk/src/org/openstreetmap/josm/tools/HttpClient.java	(revision 9232)
@@ -310,4 +310,5 @@
          * Returns the {@code Content-Encoding} header.
          * @return {@code Content-Encoding} HTTP header
+         * @see HttpURLConnection#getContentEncoding()
          */
         public String getContentEncoding() {
@@ -324,6 +325,27 @@
 
         /**
+         * Returns the {@code Expire} header.
+         * @return {@code Expire} HTTP header
+         * @see HttpURLConnection#getExpiration()
+         * @since 
+         */
+        public long getExpiration() {
+            return connection.getExpiration();
+        }
+
+        /**
+         * Returns the {@code Last-Modified} header.
+         * @return {@code Last-Modified} HTTP header
+         * @see HttpURLConnection#getLastModified()
+         * @since 9232
+         */
+        public long getLastModified() {
+            return connection.getLastModified();
+        }
+
+        /**
          * Returns the {@code Content-Length} header.
          * @return {@code Content-Length} HTTP header
+         * @see HttpURLConnection#getContentLengthLong()
          */
         public long getContentLength() {
@@ -343,12 +365,11 @@
 
         /**
-         * Returns the list of Strings that represents the named header field values.
-         * @param name the name of a header field
-         * @return unmodifiable List of Strings that represents the corresponding field values
+         * Returns an unmodifiable Map mapping header keys to a List of header values.
+         * @return unmodifiable Map mapping header keys to a List of header values
          * @see HttpURLConnection#getHeaderFields()
-         * @since 9172
-         */
-        public List<String> getHeaderFields(String name) {
-            return connection.getHeaderFields().get(name);
+         * @since 9232
+         */
+        public Map<String, List<String>> getHeaderFields() {
+            return connection.getHeaderFields();
         }
 
