Package org.eclipse.jetty.server.handler
Class ThreadLimitHandler
java.lang.Object
- All Implemented Interfaces:
Handler
,Handler.Container
,Handler.Singleton
,Request.Handler
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
,Invocable
Handler to limit the threads per IP address for DOS protection
The ThreadLimitHandler applies a limit to the number of Threads that can be used simultaneously per remote IP address.
The handler makes a determination of the remote IP separately to
any that may be made by the ForwardedRequestCustomizer
or similar:
- This handler will use only a single style of forwarded header. This is on the assumption that a trusted local proxy will produce only a single forwarded header and that any additional headers are likely from untrusted client side proxies.
- If multiple instances of a forwarded header are provided, this handler will use the right-most instance, which will have been set from the trusted local proxy
Requests in excess of the limit will be asynchronously suspended until a thread is available.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.ConditionalHandler
ConditionalHandler.Abstract, ConditionalHandler.ConnectorPredicate, ConditionalHandler.DontHandle, ConditionalHandler.ElseNext, ConditionalHandler.InetAddressPatternPredicate, ConditionalHandler.MethodPredicate, ConditionalHandler.PathSpecPredicate, ConditionalHandler.PredicateSet, ConditionalHandler.Reject, ConditionalHandler.SkipNext
Nested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract
Handler.Abstract.NonBlocking
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler
Handler.AbstractContainer, Handler.Collection, Handler.Container, Handler.Sequence, Handler.Singleton, Handler.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Request.Handler
Request.Handler.AbortException
-
Field Summary
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP
-
Constructor Summary
ConstructorDescriptionThreadLimitHandler
(String forwardedHeader) ThreadLimitHandler
(String forwardedHeader, boolean rfc7239) ThreadLimitHandler
(Handler handler, String forwardedHeader, boolean rfc7239) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doStart()
Starts the managed lifecycle beans in the order they were added.void
protected String
getRemoteIP
(Request baseRequest) int
protected int
getThreadLimit
(String ip) void
boolean
boolean
onConditionsMet
(Request request, Response response, Callback callback) Handle a request that has met the conditions.protected boolean
onConditionsNotMet
(Request request, Response response, Callback callback) This method is called when the request has not met the conditions and is not to be handled by this handler.void
setEnabled
(boolean enabled) void
setThreadLimit
(int threadLimit) Methods inherited from class org.eclipse.jetty.server.handler.ConditionalHandler
clear, dump, exclude, exclude, exclude, excludeInetAddressPattern, excludeMethod, excludePath, from, from, handle, include, include, include, includeInetAddressPattern, includeMethod, includePath, nextHandler
Methods inherited from class org.eclipse.jetty.server.Handler.Wrapper
getHandler, getInvocationType, setHandler
Methods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServer
Methods inherited from class org.eclipse.jetty.server.Handler.Abstract
destroy, doStop, getServer
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Destroyable
destroy
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.server.Handler.Container
getContainer, getDescendant, getDescendants, getDescendants
Methods inherited from interface org.eclipse.jetty.server.Handler.Singleton
getHandlers, getTail, insertHandler, setHandler
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Constructor Details
-
ThreadLimitHandler
public ThreadLimitHandler() -
ThreadLimitHandler
-
ThreadLimitHandler
-
ThreadLimitHandler
-
-
Method Details
-
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classConditionalHandler
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
isEnabled
-
setEnabled
public void setEnabled(boolean enabled) -
getThreadLimit
@ManagedAttribute("The maximum threads that can be dispatched per remote IP") public int getThreadLimit() -
getThreadLimit
-
setThreadLimit
public void setThreadLimit(int threadLimit) -
include
-
exclude
-
onConditionsMet
public boolean onConditionsMet(Request request, Response response, Callback callback) throws Exception Description copied from class:ConditionalHandler
Handle a request that has met the conditions. Typically, the implementation will provide optional handling and then call theConditionalHandler.nextHandler(Request, Response, Callback)
method to continue handling.- Specified by:
onConditionsMet
in classConditionalHandler
- Parameters:
request
- The request to handleresponse
- The response to generatecallback
- The callback for completion- Returns:
- True if this handler will complete the callback
- Throws:
Exception
- If there is a problem handling- See Also:
-
onConditionsNotMet
protected boolean onConditionsNotMet(Request request, Response response, Callback callback) throws Exception Description copied from class:ConditionalHandler
This method is called when the request has not met the conditions and is not to be handled by this handler. Implementations may return false; send an error response; or handle the request differently.- Specified by:
onConditionsNotMet
in classConditionalHandler
- Parameters:
request
- The request to handleresponse
- The response to generatecallback
- The callback for completion- Returns:
- True if this handler will complete the callback
- Throws:
Exception
- If there is a problem handling- See Also:
-
getRemoteIP
-