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