I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit ed12bcef authored by zzz's avatar zzz
Browse files

* EepGet:

  - Fix format of last-modified header to use strictest RFC 822
  - Stop immediately if socket connection to proxy fails
  - Don't forget lastModified/etag headers after redirect
  - Note SocketTimeout API breakage for Syndie
parent 41af00a7
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import java.io.InputStream; ...@@ -8,6 +8,7 @@ import java.io.InputStream;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.ConnectException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.Socket; import java.net.Socket;
import java.net.URL; import java.net.URL;
...@@ -64,6 +65,8 @@ public class EepGet { ...@@ -64,6 +65,8 @@ public class EepGet {
protected boolean _shouldWriteErrorToOutput; protected boolean _shouldWriteErrorToOutput;
protected String _etag; protected String _etag;
protected String _lastModified; protected String _lastModified;
protected final String _etagOrig;
protected final String _lastModifiedOrig;
protected boolean _encodingChunked; protected boolean _encodingChunked;
protected boolean _notModified; protected boolean _notModified;
protected String _contentType; protected String _contentType;
...@@ -142,6 +145,8 @@ public class EepGet { ...@@ -142,6 +145,8 @@ public class EepGet {
_listeners = new ArrayList(1); _listeners = new ArrayList(1);
_etag = etag; _etag = etag;
_lastModified = lastModified; _lastModified = lastModified;
_etagOrig = etag;
_lastModifiedOrig = lastModified;
} }
/** /**
...@@ -524,7 +529,8 @@ public class EepGet { ...@@ -524,7 +529,8 @@ public class EepGet {
_listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt, _numRetries, ioe); _listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt, _numRetries, ioe);
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("ERR: doFetch failed ", ioe); _log.warn("ERR: doFetch failed ", ioe);
if (ioe instanceof MalformedURLException) if (ioe instanceof MalformedURLException ||
ioe instanceof ConnectException) // proxy or nonproxied host Connection Refused
_keepFetching = false; _keepFetching = false;
} finally { } finally {
if (_out != null) { if (_out != null) {
...@@ -610,8 +616,8 @@ public class EepGet { ...@@ -610,8 +616,8 @@ public class EepGet {
// reset some important variables, we don't want to save the values from the redirect // reset some important variables, we don't want to save the values from the redirect
_bytesRemaining = -1; _bytesRemaining = -1;
_redirectLocation = null; _redirectLocation = null;
_etag = null; _etag = _etagOrig;
_lastModified = null; _lastModified = _lastModifiedOrig;
_contentType = null; _contentType = null;
_encodingChunked = false; _encodingChunked = false;
...@@ -724,8 +730,13 @@ public class EepGet { ...@@ -724,8 +730,13 @@ public class EepGet {
if (_transferFailed) { if (_transferFailed) {
// 404, etc - transferFailed is called after all attempts fail, by fetch() above // 404, etc - transferFailed is called after all attempts fail, by fetch() above
for (int i = 0; i < _listeners.size(); i++) if (!_listeners.isEmpty()) {
_listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt, _numRetries, new Exception("Attempt failed")); Exception e = new IOException("Attempt failed " + _responseCode);
for (int i = 0; i < _listeners.size(); i++) {
_listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt,
_numRetries, e);
}
}
} else if ((_minSize > 0) && (_alreadyTransferred < _minSize)) { } else if ((_minSize > 0) && (_alreadyTransferred < _minSize)) {
throw new IOException("Bytes transferred " + _alreadyTransferred + " violates minimum of " + _minSize + " bytes"); throw new IOException("Bytes transferred " + _alreadyTransferred + " violates minimum of " + _minSize + " bytes");
} else if ( (_bytesRemaining == -1) || (remaining == 0) ) { } else if ( (_bytesRemaining == -1) || (remaining == 0) ) {
......
...@@ -7,7 +7,7 @@ import java.util.Date; ...@@ -7,7 +7,7 @@ import java.util.Date;
/** /**
* This should be deprecated. * This should be deprecated.
* It is only used by EepGet. * It is only used by EepGet and Syndie.
* The only advantage seems to be a total timeout period, which is the second * The only advantage seems to be a total timeout period, which is the second
* argument to EepGet.fetch(headerTimeout, totalTimeout, inactivityTimeout), * argument to EepGet.fetch(headerTimeout, totalTimeout, inactivityTimeout),
* which is most likely always set to -1. * which is most likely always set to -1.
...@@ -52,6 +52,11 @@ public class SocketTimeout extends SimpleTimer2.TimedEvent { ...@@ -52,6 +52,11 @@ public class SocketTimeout extends SimpleTimer2.TimedEvent {
} }
} }
/**
* Change in return value from void to boolean in
* 0.9.3 accidentally broke Syndie, sorry.
* Recompile Syndie to fix it.
*/
public boolean cancel() { public boolean cancel() {
_cancelled = true; _cancelled = true;
return super.cancel(); return super.cancel();
......
...@@ -4,6 +4,7 @@ import java.text.ParseException; ...@@ -4,6 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone;
/** /**
* Moved from NewsFetcher * Moved from NewsFetcher
...@@ -13,7 +14,7 @@ public abstract class RFC822Date { ...@@ -13,7 +14,7 @@ public abstract class RFC822Date {
// SimpleDateFormat is not thread-safe, methods must be synchronized // SimpleDateFormat is not thread-safe, methods must be synchronized
private static final SimpleDateFormat OUTPUT_FORMAT = new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US); private static final SimpleDateFormat OUTPUT_FORMAT = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US);
/** /**
* http://jimyjoshi.com/blog/2007/08/rfc822dateparsinginjava.html * http://jimyjoshi.com/blog/2007/08/rfc822dateparsinginjava.html
...@@ -22,7 +23,7 @@ public abstract class RFC822Date { ...@@ -22,7 +23,7 @@ public abstract class RFC822Date {
*/ */
private static final SimpleDateFormat rfc822DateFormats[] = new SimpleDateFormat[] { private static final SimpleDateFormat rfc822DateFormats[] = new SimpleDateFormat[] {
OUTPUT_FORMAT, OUTPUT_FORMAT,
new SimpleDateFormat("EEE, d MMM yy HH:mm:ss z", Locale.US), new SimpleDateFormat("d MMM yy HH:mm:ss z", Locale.US),
new SimpleDateFormat("EEE, d MMM yy HH:mm z", Locale.US), new SimpleDateFormat("EEE, d MMM yy HH:mm z", Locale.US),
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US), new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US),
new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.US), new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.US),
...@@ -31,6 +32,16 @@ public abstract class RFC822Date { ...@@ -31,6 +32,16 @@ public abstract class RFC822Date {
new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.US) new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.US)
}; };
//
// The router JVM is forced to UTC but do this just in case
//
static {
TimeZone utc = TimeZone.getTimeZone("GMT");
for (int i = 0; i < rfc822DateFormats.length; i++) {
rfc822DateFormats[i].setTimeZone(utc);
}
}
/** /**
* new Date(String foo) is deprecated, so let's do this the hard way * new Date(String foo) is deprecated, so let's do this the hard way
* *
...@@ -56,4 +67,18 @@ public abstract class RFC822Date { ...@@ -56,4 +67,18 @@ public abstract class RFC822Date {
public synchronized static String to822Date(long t) { public synchronized static String to822Date(long t) {
return OUTPUT_FORMAT.format(new Date(t)); return OUTPUT_FORMAT.format(new Date(t));
} }
/****
public static void main(String[] args) {
if (args.length == 1) {
try {
System.out.println(to822Date(Long.parseLong(args[0])));
} catch (NumberFormatException nfe) {
System.out.println(nfe.toString());
}
} else {
System.out.println("Usage: RFC822Date numericDate");
}
}
****/
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment