MCPcopy Index your code
hub / github.com/curtcox/JLHTTP / serve

Method serve

src/main/java/net/freeutils/httpserver/HTTPServer.java:2228–2251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

handleMethodMethod · 0.95

Calls 13

serveMethod · 0.95
getMethod · 0.80
getHandlersMethod · 0.80
getMethodMethod · 0.80
sendErrorMethod · 0.80
getDirectoryIndexMethod · 0.80
setPathMethod · 0.80
addMethod · 0.80
sendMethod · 0.80
getContextMethod · 0.45
getPathMethod · 0.45
getVirtualHostMethod · 0.45

Tested by

no test coverage detected