- All Implemented Interfaces:
Handler, HandlerContainer, Container, Destroyable, Dumpable, LifeCycle
Adds a header, X-I2P-Location, to requests when they do **not** come in on an I2P hostname. This header contains a URL that looks like: [scheme://][i2phostname.i2p][/path][?query] and expresses the I2P-Equivalent URL of the clearnet query. Clients can use this to prompt users to switch from a non-I2P host to an I2P host or to redirect them automatically. It automatically enabled on the default I2P site located on port 7658 by default.
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerField Summary
FieldsFields inherited from class HandlerWrapper
_handlerFields inherited from class AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPINGConstructor Summary
ConstructorsConstructorDescriptionNo location header prefix is cached and no failure is recorded;setLocation(String)picks the prefix up from the first request that carries one.Method Summary
Modifier and TypeMethodDescriptionprivate StringgetXI2PLocation(String host, String port) Gets the location header for a target.voidhandle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) private StringheaderContents(HttpServletRequest httpRequest) Builds the header value from the request.private voidsetLocation(String xi2plocation) Caches the header value.private booleanWhether to retry the fetch after a failure.Methods inherited from class HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandlerMethods inherited from class AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerMethods inherited from class AbstractHandler
doStart, doStop, dumpThis, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
Field Details
PROP_ENABLE_LOCATION_HEADER
Config key enabling the location header.- See Also:
X_I2P_Location
The cached header value.lastFailure
private long lastFailureWhen the last fetch failed.failTimeout
private static final long failTimeoutTime before retrying after a failure.- See Also:
_log
The log for the filter.
Constructor Details
XI2PLocationFilter
public XI2PLocationFilter()No location header prefix is cached and no failure is recorded;setLocation(String)picks the prefix up from the first request that carries one.
Method Details
setLocation
Caches the header value.- Parameters:
xi2plocation- the value to cache
shouldRecheck
private boolean shouldRecheck()Whether to retry the fetch after a failure.- Returns:
- true when it is time to retry
getXI2PLocation
headerContents
Builds the header value from the request.- Parameters:
httpRequest- the request to describe- Returns:
- the header value
handle
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException - Specified by:
handlein interfaceHandler- Overrides:
handlein classHandlerWrapper- Throws:
IOExceptionServletException