Changeset df84a2f


Ignore:
Timestamp:
Nov 12, 2013 7:19:21 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b53ed94
Parents:
25e7dea
Message:

save server status text to return to user

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/EepGet.java

    r25e7dea rdf84a2f  
    1919import java.util.List;
    2020import java.util.Locale;
    21 import java.util.StringTokenizer;
    2221
    2322import net.i2p.I2PAppContext;
     
    6463    protected int _currentAttempt;
    6564    protected int _responseCode = -1;
     65    protected String _responseText;
    6666    protected boolean _shouldWriteErrorToOutput;
    6767    protected String _etag;
     
    733733            // 404, etc - transferFailed is called after all attempts fail, by fetch() above
    734734            if (!_listeners.isEmpty()) {
    735                 Exception e = new IOException("Attempt failed " + _responseCode);
     735                String s;
     736                if (_responseText != null)
     737                    s = "Attempt failed: " + _responseCode + ' ' + _responseText;
     738                else
     739                    s = "Attempt failed: " + _responseCode;
     740                Exception e = new IOException(s);
    736741                for (int i = 0; i < _listeners.size(); i++)  {
    737742                    _listeners.get(i).attemptFailed(_url, _bytesTransferred, _bytesRemaining, _currentAttempt,
     
    948953     * "HTTP/1.1 404 NOT FOUND", etc. 
    949954     *
     955     * Side effect - stores status text in _responseText
     956     *
    950957     * @return HTTP response code (200, 206, other)
    951958     */
     
    953960        if (_log.shouldLog(Log.DEBUG))
    954961            _log.debug("Status line: [" + line + "]");
    955         StringTokenizer tok = new StringTokenizer(line, " ");
    956         if (!tok.hasMoreTokens()) {
     962        String[] toks = line.split(" ", 3);
     963        if (toks.length < 2) {
    957964            if (_log.shouldLog(Log.WARN))
    958965                _log.warn("ERR: status "+  line);
    959966            return -1;
    960967        }
    961         tok.nextToken(); // ignored (protocol)
    962         if (!tok.hasMoreTokens()) {
    963             if (_log.shouldLog(Log.WARN))
    964                 _log.warn("ERR: status "+  line);
    965             return -1;
    966         }
    967         String rc = tok.nextToken();
     968        String rc = toks[1];
    968969        try {
     970            if (toks.length >= 3)
     971                _responseText = toks[2].trim();
     972            else
     973                _responseText = null;
    969974            return Integer.parseInt(rc);
    970975        } catch (NumberFormatException nfe) {
     
    11961201        return _responseCode;
    11971202    }
     1203   
     1204    /**
     1205     *  The server text ("OK", "Not Found",  etc).
     1206     *  Note that the text may contain % encoding.
     1207     *
     1208     *  @return null if invalid, or if the proxy never responded,
     1209     *  or if no proxy was used and the server never responded.
     1210     *  If a non-proxied request partially succeeded (for example a redirect followed
     1211     *  by a fail, or a partial fetch followed by a fail), this will
     1212     *  be the last status code received.
     1213     *  Note that fetch() may return false even if this returns "OK".
     1214     *
     1215      *  @since 0.9.9
     1216     */
     1217    public String getStatusText() {
     1218        return _responseText;
     1219    }
    11981220
    11991221    /**
Note: See TracChangeset for help on using the changeset viewer.