For each accepted TCP connection, the Connector asks a ConnectionFactory to create a Connection object that handles the network traffic on that TCP connection, parsing and generating bytes for a specific protocol.web
好比:a ServerConnector configured with three factories: ProxyConnectionFactory, SslConnectionFactory and HttpConnectionFactory. Such connector will be able to handle PROXY protocol bytes coming from a load balancer such as HAProxy (with the ProxyConnectionFactory), then handle TLS bytes (with SslConnectionFactory) and therefore decrypting/encrypting the bytes from/to a remote client, and finally handling HTTP/1.1 bytes (with HttpConnectionFactory).spring
能够本身自定义ConnectionFactory实现来处理自定义的协议。app
// org.eclipse.jetty.server.Handler的方法: public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException;
Handlers有两种模型:eclipse
最基层的handler,常见的就是spring的DispacherServlet + 一些Filter。ServletHandler会被 ServletContextHandler 所持有。ServletContextHandler与ServletHandler是一对一的,逻辑上就是 web application context ,即SessionHandler、SecurityHandler、ServletHandler、GzipHandler的组合,常见的就是web.xml。jvm
因为Server继承HandlerWrapper,运行时由其内部托管的handler实现(好比ServletContextHandler)。spa
注意:Server、ServletContextHandler、SessionHandler、SecurityHandler、GzipHandler、ServletHandler都是HandlerWrapper,即都在一条责任链上。
注意:ServletContextHandler、SessionHandler、ServletHandler继承ScopedHandler,即调用链上是 ScopedHandler#handle(target, request, request, response) -> ScopedHandler#doScope入参略 -> ScopedHandler#doHandlecode
因此最后请求request会传递到ServletHandler,一般会设置spring的DispatcherServlet做为ServletHandler的Servlet。server