java.lang.Object
net.i2p.util.EepGet
net.i2p.client.streaming.I2PSocketEepGet
Fetch a URL using a socket from the supplied I2PSocketManager. Hostname must resolve to an i2p destination - no routing to an outproxy. Does not support response gzip decompression (unlike I2PTunnelHTTPProxy) (yet), but of course there is still gzip at the I2CP layer. This is designed for Java apps such as bittorrent clients that wish to do HTTP fetches and use other protocols on a single set of tunnels. This may provide anonymity benefits over using the shared clients HTTP proxy, preventing inadvertent outproxy usage, reduce resource usage by eliminating a second set of tunnels, and eliminate the requirement to to separately configure the proxy host and port. For additional documentation see the superclass. Supports http://example.i2p/blah Supports http://B32KEY.b32.i2p/blah Supports http://i2p/B64KEY/blah for compatibility with the eepproxy Supports http://B64KEY/blah Warning - does not support /eepproxy/blah, address helpers, http://B64KEY.i2p/blah, or other odd things that may be found in the HTTP proxy.
Nested Class Summary
Nested classes/interfaces inherited from class EepGet
EepGet.AUTH_MODE, EepGet.AuthState, EepGet.CLIStatusListener, EepGet.Gunzipper, EepGet.StatusListenerModifier and TypeClassDescriptionprotected static enumAuthentication mode enumeration.protected classManage the authentication parameters Ref: RFC 2617 Supports both Basic and Digest, however i2ptunnel HTTP proxy has migrated all previous Basic support to Digest.protected classReports fetch progress to the command line, one mark per markSize bytes and a summary line every lineSize marks.protected classDecompressor thread.static interfaceCallback interface for monitoring EepGet transfer progress.Field Summary
Fields inherited from class EepGet
_aborted, _acceptRanges, _actualURL, _alreadyTransferred, _authState, _bytesRemaining, _bytesTransferred, _cacheControl, _contentEncoding, _contentLanguage, _contentRange, _contentType, _context, _cookie, _csp, _currentAttempt, _decompressException, _encodingChunked, _etag, _etagOrig, _expiryDate, _extraHeaders, _fetchHeaderTimeout, _fetchInactivityTimeout, _fetchTotalTimeout, _isGzippedResponse, _keepFetching, _lastModified, _lastModifiedOrig, _listeners, _log, _maxCompleteFails, _notModified, _numRetries, _out, _outputFile, _outputStream, _proxy, _proxyHost, _proxyIn, _proxyOut, _proxyPort, _redirectLocation, _redirects, _referrerPolicy, _responseCode, _responseText, _retryDelayMs, _server, _shouldProxy, _shouldWriteErrorToOutput, _status, _transferEncoding, _transferFailed, _url, _vary, _xContentTypeOptions, _xframeOptions, _xPoweredBy, _xssProtection, DEFAULT_CONNECT_TIMEOUT, DEFAULT_INACTIVITY_TIMEOUT, DEFAULT_MAX_COMPLETE_FAILS, DEFAULT_NUM_RETRIES, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_JITTER, USER_AGENTModifier and TypeFieldDescriptionprotected booleanWhether the fetch was aborted due to timeout or user request.protected StringAccept-Ranges header value from the response.protected StringThe URL we actually fetch from (may differ from _url in case of redirect).protected longTotal bytes transferred across all attempts, including resumed content.protected EepGet.AuthStateAuthentication state for proxy digest/basic auth; created viaEepGet.addAuthorization(String, String).protected longRemaining bytes on the current attempt, -1 if unknown (chunked or no Content-Length).protected longBody bytes transferred in the currentEepGet.fetch(), summed across attempts.protected StringCache-Control header value from the response.protected StringContent-Encoding header value from the response.protected StringContent-Language header value from the response.protected StringContent-Range header value from the response, for validating 206/416 resumes.protected StringContent-Type header value from the response.protected final I2PAppContextI2P application context for configuration, logging, and random number generation.protected StringSet-Cookie header value from the response.protected StringContent-Security-Policy header value from the response.protected intZero-based attempt counter for the current fetch; read by the watchdog command.protected IOExceptionIOException from the background decompressor thread, if any.protected booleanWhether the response is using chunked transfer encoding.protected StringETag received from the server (for conditional requests).protected final StringOriginal ETag passed in constructor, preserved across redirects.protected StringExpires header value from the response.Additional HTTP headers to include in the request.protected intTimeout in ms for receiving the HTTP response headers.protected intInactivity timeout in ms between data packets.protected intTotal timeout in ms for the entire fetch operation.protected booleanWhether the response body is gzip-compressed.protected booleanWhether to continue fetching; set false to abort.protected StringLast-Modified header received from the server.protected final StringOriginal Last-Modified passed in constructor, preserved across redirects.protected final List<EepGet.StatusListener> Registered status listeners for progress callbacks.protected final LogLogger for this instance.protected intMaximum number of complete (zero-byte) failures before giving up.protected booleanWhether the server returned 304 Not Modified.protected final intMaximum number of retry attempts per fetch.protected OutputStreamOutput stream for writing fetched data (file or pipe).protected final StringPath to the output file for saving the fetched content.protected final OutputStreamOutput stream destination, overrides outputFile when non-null.protected SocketThe socket connection to the proxy or the target server (if not proxied).protected final StringProxy hostname or IP address.protected InputStreamInput stream from the proxy/server socket.protected OutputStreamOutput stream to the proxy/server socket.protected final intProxy port number.protected StringLocation header value from redirect or 407 proxy auth response.protected AtomicIntegerCounter tracking the number of HTTP redirects followed.protected StringReferrer-Policy header value from the response.protected intHTTP response status code, -1 if no response received.protected StringHTTP response status text (e.g.protected final longFixed retry delay in ms, -1 selects the jittered default @since 0.9.71+.protected StringServer header value from the response.protected final booleanWhether to route requests through an HTTP proxy.protected booleanWhether to write error response bodies to the output.protected StringStatus header value from the response.protected StringTransfer-Encoding header value from the response.protected booleanWhether the current transfer attempt failed (non-2xx response code).protected final StringThe URL we were asked to fetch.protected StringVary header value from the response.protected StringX-Content-Type-Options header value from the response.protected StringX-Frame-Options header value from the response.protected StringX-Powered-By header value from the response.protected StringX-XSS-Protection header value from the response.protected static final intDefault connect timeout in milliseconds (90 seconds).protected static final intDefault inactivity timeout in milliseconds (5 minutes).protected static final intMaximum times to try without getting any data at all, even if numRetries is higher @since 0.7.14.protected static final intDefault number of retry attempts.protected static final intBase retry delay in milliseconds when the jittered default is used @since 0.9.71+.protected static final intMaximum additional jitter in milliseconds added to the base retry delay @since 0.9.71+.protected static final StringDefault User-Agent header value.Constructor Summary
ConstructorsConstructorDescriptionI2PSocketEepGet(I2PAppContext ctx, I2PSocketManager mgr, int numRetries, long minSize, long maxSize, String outputFile, OutputStream outputStream, String url) Creates an I2PSocketEepGet with full configuration.I2PSocketEepGet(I2PAppContext ctx, I2PSocketManager mgr, int numRetries, String outputFile, String url) Creates an I2PSocketEepGet with default size limits.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanfetch(long fetchHeaderTimeout, long totalTimeout, long inactivityTimeout) We have to override this to close _socket, since we can't use _proxy in super as the I2PSocket.protected StringGuess we have to override this since super doesn't strip the http://host from the GET line which hoses some servers (opentracker) HTTP proxy was kind enough to do this for us.protected voidOverridden to disable inline gunzipping.protected voidsendRequest(SocketTimeout timeout) Look up the address, get a socket from the I2PSocketManager supplied in the constructor, and send the request.Methods inherited from class EepGet
addAuthorization, addHeader, addStatusListener, doFetch, fetch, fetch, getAcceptRanges, getCacheControl, getContentEncoding, getContentLanguage, getContentType, getCookie, getCSP, getEtag, getExpiryDate, getLastModified, getNotModified, getReferrerPolicy, getResumeOffset, getServer, getStatus, getStatusCode, getStatusText, getTransferEncoding, getVary, getXContentTypeOptions, getXframeOptions, getXPoweredBy, getXSSProtection, main, parseAuthArgs, readChunkLength, setPostData, setPostData, setPostData, setWriteErrorToOutput, shouldReadBody, stopFetching, suggestNameModifier and TypeMethodDescriptionvoidaddAuthorization(String userName, String password) Add basic authorization header for the proxy.voidAdd an extra header to the request.voidAdd a status listener.protected voiddoFetch(SocketTimeout timeout) Read response body for a single fetch.booleanfetch()Blocking fetch, returning true if the URL was retrieved, false if all retries failed.booleanfetch(long fetchHeaderTimeout) Blocking fetch, timing out individual attempts if the HTTP response headers don't come back in the time given.Show the Accept-Ranges field.Show the Cache-Control field.Show the Content-Encoding field.Show the Content-Language field.After fetch, the received value from the server, or null if none.Show the Set-Cookie field.getCSP()Content-Security-Policy header.getEtag()After fetch, the received value from the server, or null if none.Show the Expires field.After fetch, the received value from the server, or null if none.booleanWhether the server returned 304.Referrer-Policy header.protected longgetResumeOffset(File outFile) Byte offset to resume from for a file-based fetch, accounting for the persisted gunzip state: a marker means the file holds decompressed bytes, whose length is not a valid offset into the compressed representation, so the fetch restarts instead of resuming.Show the Server field.Combined server status message e.g.intThe server response (200, etc).The server text ("OK", "Not Found", etc).Show the Transfer-Encoding field.getVary()Vary header.X-Content-Type-Options header.X-Frame-Options header.X-Powered-By header.X-XSS-Protection header.static voidCommand-line entry point for EepGet.parseAuthArgs(String args) Parse the args in an authentication header.protected longParse a chunk length from the HTTP response stream.protected voidsetPostData(String contentType, byte[] data) Set post data (binary body).protected voidsetPostData(String contentType, File data) Set post data (file body).protected voidsetPostData(String contentType, String data) Set post data (string body).voidIf 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).protected booleanWhether to read the response body.voidStop the fetch in progress.static StringsuggestName(String url) Parse URL for a viable filename.
Constructor Details
I2PSocketEepGet
public I2PSocketEepGet(I2PAppContext ctx, I2PSocketManager mgr, int numRetries, String outputFile, String url) Creates an I2PSocketEepGet with default size limits.- Parameters:
ctx- the I2P app contextmgr- the socket managernumRetries- number of retries on failureoutputFile- file to write output tourl- the URL to fetch
I2PSocketEepGet
public I2PSocketEepGet(I2PAppContext ctx, I2PSocketManager mgr, int numRetries, long minSize, long maxSize, String outputFile, OutputStream outputStream, String url) Creates an I2PSocketEepGet with full configuration.- Parameters:
ctx- the I2P app contextmgr- the socket managernumRetries- number of retries on failureminSize- minimum acceptable sizemaxSize- maximum acceptable sizeoutputFile- file to write output tooutputStream- stream to write output tourl- the URL to fetch
Method Details
fetch
public boolean fetch(long fetchHeaderTimeout, long totalTimeout, long inactivityTimeout) We have to override this to close _socket, since we can't use _proxy in super as the I2PSocket.- Overrides:
fetchin classEepGet- Parameters:
fetchHeaderTimeout- <= 0 for none (proxy will timeout if none, none isn't recommended if no proxy) forced to totalTimeout if totalTimeout is set and this is <= 0totalTimeout- operation-wide deadline for the whole fetch, including retries and backoff between attempts; <= 0 for default noneinactivityTimeout- <= 0 for defaultEepGet.DEFAULT_INACTIVITY_TIMEOUT(5 minutes)- Returns:
- whether the URL was retrieved; false if every attempt failed
readHeaders
Overridden to disable inline gunzipping.- Overrides:
readHeadersin classEepGet- Throws:
IOException- on IO error
sendRequest
Look up the address, get a socket from the I2PSocketManager supplied in the constructor, and send the request.- Overrides:
sendRequestin classEepGet- Parameters:
timeout- connect and inactivity timeout, used to detect hung connections- Throws:
IOException- on IO error
getRequest
Guess we have to override this since super doesn't strip the http://host from the GET line which hoses some servers (opentracker) HTTP proxy was kind enough to do this for us.- Overrides:
getRequestin classEepGet- Returns:
- the HTTP request line and headers, with the scheme and host stripped from the GET line
- Throws:
IOException- on bad URL