From 393d813d05803fb84a922374335e8e7e7650107d Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 27 May 2011 21:41:49 +0000 Subject: [PATCH] Don't re-append the query string to the redirect URL, which caused eepget to repeatedly retry the new redirect of an i2paddresshelper query by the HTTP proxy. This was clearly non-compliant (the Location: header requires an absolute URI including any query string). This was part of the original redirect handling added by jrandom to eepget back when it was in syndie; appending that changelog just in case this hackery was required by Freenet USKs, which I doubt. Also, reset the redirect counter when retrying. ============== Revision: 62a8cac8565958d111d0a47a443c964918d2e3ef Parent: 277fe109ea4416f7d8a6dba6e09cd4f605a8ce1a Author: jrandom@i2p.net Date: 10/22/2006 15:06:30 Branch: i2p.syndie Changelog: ... - add support for HTTP 301 redirects to EepGet (so freenet USKs work as intended) --- core/java/src/net/i2p/util/EepGet.java | 15 ++++++--------- core/java/src/net/i2p/util/EepHead.java | 14 +++++--------- history.txt | 3 +++ router/java/src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java index 955ae8238..45622a002 100644 --- a/core/java/src/net/i2p/util/EepGet.java +++ b/core/java/src/net/i2p/util/EepGet.java @@ -474,6 +474,7 @@ public class EepGet { (_alreadyTransferred == 0 && _currentAttempt > MAX_COMPLETE_FAILS) || !_keepFetching) break; + _redirects = 0; try { long delay = _context.random().nextInt(60*1000); Thread.sleep(5*1000+delay); @@ -512,22 +513,18 @@ public class EepGet { if (_redirectLocation != null) { //try { - URL oldURL = new URL(_actualURL); - String query = oldURL.getQuery(); - if (query == null) query = ""; if (_redirectLocation.startsWith("http://")) { - if ( (_redirectLocation.indexOf('?') < 0) && (query.length() > 0) ) - _actualURL = _redirectLocation + "?" + query; - else - _actualURL = _redirectLocation; + _actualURL = _redirectLocation; } else { + // the Location: field has been required to be an absolute URI at least since + // RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is. + // This oddly adds a ":" even if no port, but that seems to work. URL url = new URL(_actualURL); if (_redirectLocation.startsWith("/")) _actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation; else + // this blows up completely on a redirect to https://, for example _actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation; - if ( (_actualURL.indexOf('?') < 0) && (query.length() > 0) ) - _actualURL = _actualURL + "?" + query; } // an MUE is an IOE //} catch (MalformedURLException mue) { diff --git a/core/java/src/net/i2p/util/EepHead.java b/core/java/src/net/i2p/util/EepHead.java index bb8304a39..c4850e8c6 100644 --- a/core/java/src/net/i2p/util/EepHead.java +++ b/core/java/src/net/i2p/util/EepHead.java @@ -121,22 +121,18 @@ public class EepHead extends EepGet { // Should we even follow redirects for HEAD? if (_redirectLocation != null) { //try { - URL oldURL = new URL(_actualURL); - String query = oldURL.getQuery(); - if (query == null) query = ""; if (_redirectLocation.startsWith("http://")) { - if ( (_redirectLocation.indexOf('?') < 0) && (query.length() > 0) ) - _actualURL = _redirectLocation + "?" + query; - else - _actualURL = _redirectLocation; + _actualURL = _redirectLocation; } else { + // the Location: field has been required to be an absolute URI at least since + // RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is. + // This oddly adds a ":" even if no port, but that seems to work. URL url = new URL(_actualURL); if (_redirectLocation.startsWith("/")) _actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation; else + // this blows up completely on a redirect to https://, for example _actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation; - if ( (_actualURL.indexOf('?') < 0) && (query.length() > 0) ) - _actualURL = _actualURL + "?" + query; } // an MUE is an IOE //} catch (MalformedURLException mue) { diff --git a/history.txt b/history.txt index a62c93347..31218b962 100644 --- a/history.txt +++ b/history.txt @@ -2,6 +2,9 @@ * Console: Fix router.updateThroughProxy being set to false after saving change on /configupdate when install dir is read-only. (ticket #466) + * EepGet: + - Fix redirect loop (thx kytv) + - Reset redirect counter when retrying * JBigI: - Refactor to handle 64 bit libs and a list of fallback libs - Logging tweaks diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index f2522cd4e..7ca1a3ec2 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 9; + public final static long BUILD = 10; /** for example "-test" */ public final static String EXTRA = ""; -- GitLab