public class EepGet extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
EepGet.AUTH_MODE |
protected class |
EepGet.AuthState
Manage the authentication parameters
Ref: RFC 2617
Supports both Basic and Digest, however i2ptunnel HTTP proxy
has migrated all previous Basic support to Digest.
|
protected class |
EepGet.CLIStatusListener |
protected class |
EepGet.Gunzipper
Decompressor thread.
|
static interface |
EepGet.StatusListener |
Modifier and Type | Field and Description |
---|---|
protected boolean |
_aborted |
protected String |
_actualURL
the URL we actually fetch from (may differ from the _url in case of redirect)
|
protected long |
_alreadyTransferred |
protected EepGet.AuthState |
_authState |
protected long |
_bytesRemaining |
protected long |
_bytesTransferred |
protected String |
_contentType |
protected I2PAppContext |
_context |
protected int |
_currentAttempt |
protected IOException |
_decompressException |
protected boolean |
_encodingChunked |
protected String |
_etag |
protected String |
_etagOrig |
protected List<String> |
_extraHeaders |
protected int |
_fetchHeaderTimeout |
protected int |
_fetchInactivityTimeout |
protected boolean |
_headersRead |
protected boolean |
_isGzippedResponse |
protected boolean |
_keepFetching |
protected String |
_lastModified |
protected String |
_lastModifiedOrig |
protected List<EepGet.StatusListener> |
_listeners |
protected Log |
_log |
protected boolean |
_notModified |
protected int |
_numRetries |
protected OutputStream |
_out |
protected String |
_outputFile |
protected OutputStream |
_outputStream |
protected Socket |
_proxy |
protected InputStream |
_proxyIn |
protected OutputStream |
_proxyOut |
protected String |
_redirectLocation |
protected int |
_redirects |
protected int |
_responseCode |
protected String |
_responseText |
protected boolean |
_shouldProxy |
protected boolean |
_shouldWriteErrorToOutput |
protected boolean |
_transferFailed |
protected String |
_url
url we were asked to fetch
|
protected static int |
CONNECT_TIMEOUT |
protected static int |
INACTIVITY_TIMEOUT |
protected static int |
MAX_COMPLETE_FAILS
maximum times to try without getting any data at all, even if numRetries is higher @since 0.7.14
|
protected static String |
USER_AGENT
this will be replaced by the HTTP Proxy if we are using it
|
Constructor and Description |
---|
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
long minSize,
long maxSize,
String outputFile,
OutputStream outputStream,
String url,
boolean allowCaching,
String etag,
String postData) |
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
long minSize,
long maxSize,
String outputFile,
OutputStream outputStream,
String url,
boolean allowCaching,
String etag,
String lastModified,
String postData) |
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url) |
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url,
boolean allowCaching,
String etag) |
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url,
boolean allowCaching,
String etag,
String lastModified) |
EepGet(I2PAppContext ctx,
boolean shouldProxy,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url,
String postData) |
EepGet(I2PAppContext ctx,
int numRetries,
String outputFile,
String url) |
EepGet(I2PAppContext ctx,
int numRetries,
String outputFile,
String url,
boolean allowCaching) |
EepGet(I2PAppContext ctx,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url) |
EepGet(I2PAppContext ctx,
String proxyHost,
int proxyPort,
int numRetries,
String outputFile,
String url,
boolean allowCaching) |
Modifier and Type | Method and Description |
---|---|
void |
addAuthorization(String userName,
String password)
Add basic authorization header for the proxy.
|
void |
addHeader(String name,
String value)
Add an extra header to the request.
|
void |
addStatusListener(EepGet.StatusListener lsnr) |
protected void |
doFetch(SocketTimeout timeout)
single fetch
|
boolean |
fetch()
Blocking fetch, returning true if the URL was retrieved, false if all retries failed.
|
boolean |
fetch(long fetchHeaderTimeout)
Blocking fetch, timing out individual attempts if the HTTP response headers
don't come back in the time given.
|
boolean |
fetch(long fetchHeaderTimeout,
long totalTimeout,
long inactivityTimeout)
Blocking fetch.
|
String |
getContentType()
After fetch, the received value from the server, or null if none.
|
String |
getETag()
After fetch, the received value from the server, or null if none.
|
String |
getLastModified()
After fetch, the received value from the server, or null if none.
|
boolean |
getNotModified() |
protected String |
getRequest() |
int |
getStatusCode()
The server response (200, etc).
|
String |
getStatusText()
The server text ("OK", "Not Found", etc).
|
static void |
main(String[] args)
EepGet [-p 127.0.0.1:4444] [-n #retries] [-e etag] [-o outputFile] [-m markSize lineLen] url
|
static Map<String,String> |
parseAuthArgs(String args)
Parse the args in an authentication header.
|
protected long |
readChunkLength() |
protected void |
readHeaders() |
protected void |
sendRequest(SocketTimeout timeout) |
void |
setWriteErrorToOutput()
If called (before calling fetch()),
data from the server or proxy will be written to the
output file or stream even on an error response code (4xx, 5xx, etc).
|
void |
stopFetching() |
static String |
suggestName(String url)
Parse URL for a viable filename.
|
protected final I2PAppContext _context
protected final Log _log
protected final boolean _shouldProxy
protected final int _numRetries
protected final String _outputFile
protected final OutputStream _outputStream
protected final String _url
protected String _actualURL
protected final List<EepGet.StatusListener> _listeners
protected boolean _keepFetching
protected Socket _proxy
protected OutputStream _proxyOut
protected InputStream _proxyIn
protected OutputStream _out
protected long _alreadyTransferred
protected long _bytesTransferred
protected long _bytesRemaining
protected int _currentAttempt
protected int _responseCode
protected String _responseText
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
protected boolean _transferFailed
protected boolean _headersRead
protected boolean _aborted
protected int _fetchHeaderTimeout
protected int _fetchInactivityTimeout
protected int _redirects
protected String _redirectLocation
protected boolean _isGzippedResponse
protected IOException _decompressException
protected EepGet.AuthState _authState
protected static final String USER_AGENT
protected static final int CONNECT_TIMEOUT
protected static final int INACTIVITY_TIMEOUT
protected static final int MAX_COMPLETE_FAILS
public EepGet(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String outputFile, String url)
public EepGet(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, boolean allowCaching)
public EepGet(I2PAppContext ctx, int numRetries, String outputFile, String url)
public EepGet(I2PAppContext ctx, int numRetries, String outputFile, String url, boolean allowCaching)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, String postData)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, boolean allowCaching, String etag)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, String outputFile, String url, boolean allowCaching, String etag, String lastModified)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, long minSize, long maxSize, String outputFile, OutputStream outputStream, String url, boolean allowCaching, String etag, String postData)
public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, long minSize, long maxSize, String outputFile, OutputStream outputStream, String url, boolean allowCaching, String etag, String lastModified, String postData)
public static void main(String[] args)
public static String suggestName(String url)
url
- a URL giving the location of an online resourcepublic void addStatusListener(EepGet.StatusListener lsnr)
public void stopFetching()
public boolean fetch()
public boolean fetch(long fetchHeaderTimeout)
public boolean fetch(long fetchHeaderTimeout, long totalTimeout, long inactivityTimeout)
fetchHeaderTimeout
- <= 0 for none (proxy will timeout if none, none isn't recommended if no proxy)totalTimeout
- <= 0 for default noneinactivityTimeout
- <= 0 for default 60 secprotected void doFetch(SocketTimeout timeout) throws IOException
timeout
- may be nullIOException
protected void readHeaders() throws IOException
IOException
protected long readChunkLength() throws IOException
IOException
protected void sendRequest(SocketTimeout timeout) throws IOException
timeout
- may be nullIOException
protected String getRequest() throws IOException
IOException
public String getETag()
public String getLastModified()
public boolean getNotModified()
public String getContentType()
public int getStatusCode()
public String getStatusText()
public void setWriteErrorToOutput()
public void addHeader(String name, String value)
public void addAuthorization(String userName, String password)
public static Map<String,String> parseAuthArgs(String args)
args
- non-null, starting after "Digest " or "Basic "