From a0befe59c32b41300c23925d4af2d7c459c00067 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 31 Jan 2013 12:54:23 +0000 Subject: [PATCH] * EepGet: - Fix URL when not proxied to conform to RFC 2616 - Add port to Host header to conform to RFC 2616 --- core/java/src/net/i2p/util/EepGet.java | 36 ++++++++++++------- core/java/src/net/i2p/util/EepHead.java | 32 +++++++++++------ core/java/src/net/i2p/util/PartialEepGet.java | 32 +++++++++++------ history.txt | 5 +++ .../src/net/i2p/router/RouterVersion.java | 2 +- 5 files changed, 74 insertions(+), 33 deletions(-) diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java index 2198486cc6..b0f993207a 100644 --- a/core/java/src/net/i2p/util/EepGet.java +++ b/core/java/src/net/i2p/util/EepGet.java @@ -1087,24 +1087,36 @@ public class EepGet { if ( (_postData != null) && (_postData.length() > 0) ) post = true; URL url = new URL(_actualURL); - String proto = url.getProtocol(); String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); - if (query != null) - path = path + '?' + query; - if (!path.startsWith("/")) - path = "/" + path; - if ( (port == 80) || (port == 443) || (port <= 0) ) path = proto + "://" + host + path; - else path = proto + "://" + host + ":" + port + path; - if (_log.shouldLog(Log.DEBUG)) _log.debug("Requesting " + path); - if (post) { - buf.append("POST ").append(_actualURL).append(" HTTP/1.1\r\n"); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Requesting " + _actualURL); + // RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied + String urlToSend; + if (_shouldProxy) { + urlToSend = _actualURL; + if ((path == null || path.length()<= 0) && + (query == null || query.length()<= 0)) + urlToSend += "/"; } else { - buf.append("GET ").append(_actualURL).append(" HTTP/1.1\r\n"); + urlToSend = path; + if (urlToSend == null || urlToSend.length()<= 0) + urlToSend = "/"; + if (query != null) + urlToSend += '?' + query; } - buf.append("Host: ").append(url.getHost()).append("\r\n"); + if (post) { + buf.append("POST ").append(urlToSend).append(" HTTP/1.1\r\n"); + } else { + buf.append("GET ").append(urlToSend).append(" HTTP/1.1\r\n"); + } + // RFC 2616 sec 5.1.2 - host + port (NOT authority, which includes userinfo) + buf.append("Host: ").append(host); + if (port >= 0) + buf.append(':').append(port); + buf.append("\r\n"); if (_alreadyTransferred > 0) { buf.append("Range: bytes="); buf.append(_alreadyTransferred); diff --git a/core/java/src/net/i2p/util/EepHead.java b/core/java/src/net/i2p/util/EepHead.java index 13c4c57ed3..5365040883 100644 --- a/core/java/src/net/i2p/util/EepHead.java +++ b/core/java/src/net/i2p/util/EepHead.java @@ -183,20 +183,32 @@ public class EepHead extends EepGet { protected String getRequest() throws IOException { StringBuilder buf = new StringBuilder(512); URL url = new URL(_actualURL); - String proto = url.getProtocol(); String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); - if (query != null) - path = path + "?" + query; - if (!path.startsWith("/")) - path = "/" + path; - if ( (port == 80) || (port == 443) || (port <= 0) ) path = proto + "://" + host + path; - else path = proto + "://" + host + ":" + port + path; - if (_log.shouldLog(Log.DEBUG)) _log.debug("Requesting " + path); - buf.append("HEAD ").append(_actualURL).append(" HTTP/1.1\r\n"); - buf.append("Host: ").append(url.getHost()).append("\r\n"); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Requesting " + _actualURL); + // RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied + String urlToSend; + if (_shouldProxy) { + urlToSend = _actualURL; + if ((path == null || path.length()<= 0) && + (query == null || query.length()<= 0)) + urlToSend += "/"; + } else { + urlToSend = path; + if (urlToSend == null || urlToSend.length()<= 0) + urlToSend = "/"; + if (query != null) + urlToSend += '?' + query; + } + buf.append("HEAD ").append(urlToSend).append(" HTTP/1.1\r\n"); + // RFC 2616 sec 5.1.2 - host + port (NOT authority, which includes userinfo) + buf.append("Host: ").append(host); + if (port >= 0) + buf.append(':').append(port); + buf.append("\r\n"); buf.append("Accept-Encoding: \r\n"); // This will be replaced if we are going through I2PTunnelHTTPClient buf.append("User-Agent: " + USER_AGENT + "\r\n"); diff --git a/core/java/src/net/i2p/util/PartialEepGet.java b/core/java/src/net/i2p/util/PartialEepGet.java index cf3fe673e6..d557137307 100644 --- a/core/java/src/net/i2p/util/PartialEepGet.java +++ b/core/java/src/net/i2p/util/PartialEepGet.java @@ -95,20 +95,32 @@ public class PartialEepGet extends EepGet { protected String getRequest() throws IOException { StringBuilder buf = new StringBuilder(2048); URL url = new URL(_actualURL); - String proto = url.getProtocol(); String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); - if (query != null) - path = path + '?' + query; - if (!path.startsWith("/")) - path = "/" + path; - if ( (port == 80) || (port == 443) || (port <= 0) ) path = proto + "://" + host + path; - else path = proto + "://" + host + ":" + port + path; - if (_log.shouldLog(Log.DEBUG)) _log.debug("Requesting " + path); - buf.append("GET ").append(_actualURL).append(" HTTP/1.1\r\n"); - buf.append("Host: ").append(url.getHost()).append("\r\n"); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Requesting " + _actualURL); + // RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied + String urlToSend; + if (_shouldProxy) { + urlToSend = _actualURL; + if ((path == null || path.length()<= 0) && + (query == null || query.length()<= 0)) + urlToSend += "/"; + } else { + urlToSend = path; + if (urlToSend == null || urlToSend.length()<= 0) + urlToSend = "/"; + if (query != null) + urlToSend += '?' + query; + } + buf.append("GET ").append(urlToSend).append(" HTTP/1.1\r\n"); + // RFC 2616 sec 5.1.2 - host + port (NOT authority, which includes userinfo) + buf.append("Host: ").append(host); + if (port >= 0) + buf.append(':').append(port); + buf.append("\r\n"); buf.append("Range: bytes="); buf.append(_alreadyTransferred); buf.append('-'); diff --git a/history.txt b/history.txt index 3169c91612..fb38bf247a 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,8 @@ +2013-01-31 zzz + * EepGet: + - Fix URL when not proxied to conform to RFC 2616 + - Add port to Host header to conform to RFC 2616 + 2013-01-29 zzz * Console: Catch IllegalStateException storing nonces (ticket #852) * Translations: diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index a6204817e3..f2522cd4ed 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 = 8; + public final static long BUILD = 9; /** for example "-test" */ public final static String EXTRA = "";