Serves the content for a request by invoking the context handler for the requested context (path) and HTTP method. @param req the request @param resp the response into which the content is written @throws IOException if an error occurs
(Request req, Response resp)
| 2226 | * @throws IOException if an error occurs |
| 2227 | */ |
| 2228 | protected void serve(Request req, Response resp) throws IOException { |
| 2229 | // get context handler to handle request |
| 2230 | ContextHandler handler = req.getContext().getHandlers().get(req.getMethod()); |
| 2231 | if (handler == null) { |
| 2232 | resp.sendError(404); |
| 2233 | return; |
| 2234 | } |
| 2235 | // serve request |
| 2236 | int status = 404; |
| 2237 | // add directory index if necessary |
| 2238 | String path = req.getPath(); |
| 2239 | if (path.endsWith("/")) { |
| 2240 | String index = req.getVirtualHost().getDirectoryIndex(); |
| 2241 | if (index != null) { |
| 2242 | req.setPath(path + index); |
| 2243 | status = handler.serve(req, resp); |
| 2244 | req.setPath(path); |
| 2245 | } |
| 2246 | } |
| 2247 | if (status == 404) |
| 2248 | status = handler.serve(req, resp); |
| 2249 | if (status > 0) |
| 2250 | resp.sendError(status); |
| 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * Adds a Content-Type mapping for the given path suffixes. |
no test coverage detected