From bf832a407e08fdca130d76c8075179af6b7542ac Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 1 Jul 2011 11:04:09 +0000
Subject: [PATCH]   * EepGet:     - Fix error output bug     - Output error
 data for 504 too

---
 core/java/src/net/i2p/util/EepGet.java | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java
index 25116721a6..c5edd976f3 100644
--- a/core/java/src/net/i2p/util/EepGet.java
+++ b/core/java/src/net/i2p/util/EepGet.java
@@ -703,7 +703,7 @@ public class EepGet {
             case 409: // bad addr helper
             case 503: // no outproxy
                 _transferFailed = true;
-                if (_alreadyTransferred == 0 && !_shouldWriteErrorToOutput) {
+                if (_alreadyTransferred > 0 || !_shouldWriteErrorToOutput) {
                     _keepFetching = false;
                     return;
                 }
@@ -718,7 +718,7 @@ public class EepGet {
                 break;
             case 416: // completed (or range out of reach)
                 _bytesRemaining = 0;
-                if (_alreadyTransferred == 0 && !_shouldWriteErrorToOutput) {
+                if (_alreadyTransferred > 0 || !_shouldWriteErrorToOutput) {
                     _keepFetching = false;
                     return;
                 }
@@ -732,10 +732,24 @@ public class EepGet {
                 }
                 break;
             case 504: // gateway timeout
-                // throw out of doFetch() to fetch() and try again
-                throw new IOException("HTTP Proxy timeout");
+                if (_alreadyTransferred > 0 || (!_shouldWriteErrorToOutput) ||
+                    _currentAttempt < _numRetries) {
+                    // throw out of doFetch() to fetch() and try again
+                    // why throw???
+                    throw new IOException("HTTP Proxy timeout");
+                }
+                // output the error data to the stream
+                rcOk = true;
+                if (_out == null) {
+                    if (_outputStream != null)
+                        _out = _outputStream;
+                    else
+                        _out = new FileOutputStream(_outputFile, true);
+                }
+                _transferFailed = true;
+                break;
             default:
-                if (_alreadyTransferred == 0 && !_shouldWriteErrorToOutput) {
+                if (_alreadyTransferred > 0 || !_shouldWriteErrorToOutput) {
                     _keepFetching = false;
                 } else {
                     // output the error data to the stream
-- 
GitLab