* 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
This commit is contained in:
zzz
2013-01-12 18:12:35 +00:00
parent 41af00a7d6
commit ed12bcefdb
3 changed files with 49 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
@@ -64,6 +65,8 @@ public class EepGet {
protected boolean _shouldWriteErrorToOutput;
protected String _etag;
protected String _lastModified;
protected final String _etagOrig;
protected final String _lastModifiedOrig;
protected boolean _encodingChunked;
protected boolean _notModified;
protected String _contentType;
@@ -142,6 +145,8 @@ public class EepGet {
_listeners = new ArrayList(1);
_etag = etag;
_lastModified = lastModified;
_etagOrig = etag;
_lastModifiedOrig = lastModified;
}
/**
@@ -524,7 +529,8 @@ public class EepGet {
_listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt, _numRetries, ioe);
if (_log.shouldLog(Log.WARN))
_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;
} finally {
if (_out != null) {
@@ -610,8 +616,8 @@ public class EepGet {
// reset some important variables, we don't want to save the values from the redirect
_bytesRemaining = -1;
_redirectLocation = null;
_etag = null;
_lastModified = null;
_etag = _etagOrig;
_lastModified = _lastModifiedOrig;
_contentType = null;
_encodingChunked = false;
@@ -724,8 +730,13 @@ public class EepGet {
if (_transferFailed) {
// 404, etc - transferFailed is called after all attempts fail, by fetch() above
for (int i = 0; i < _listeners.size(); i++)
_listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt, _numRetries, new Exception("Attempt failed"));
if (!_listeners.isEmpty()) {
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)) {
throw new IOException("Bytes transferred " + _alreadyTransferred + " violates minimum of " + _minSize + " bytes");
} else if ( (_bytesRemaining == -1) || (remaining == 0) ) {

View File

@@ -7,7 +7,7 @@ import java.util.Date;
/**
* 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
* argument to EepGet.fetch(headerTimeout, totalTimeout, inactivityTimeout),
* which is most likely always set to -1.
@@ -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() {
_cancelled = true;
return super.cancel();