@Override public Response length(final long length) { rsp.length(length); return this; }
/** * Transfer the file at path as an "attachment". Typically, browsers will prompt the user for * download. The <code>Content-Disposition</code> "filename=" parameter (i.e. the one that will * appear in the browser dialog) is set to filename. * * @param filename A file name to use. * @param file A file to use. * @throws Exception If something goes wrong. */ default void download(final String filename, final File file) throws Throwable { length(file.length()); download(filename, new FileInputStream(file)); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String CRLF = "\r\n"; StringBuilder buffer = new StringBuilder("TRACE ").append(req.path()) .append(" ").append(req.protocol()); for (Entry<String, Mutant> entry : req.headers().entrySet()) { buffer.append(CRLF).append(entry.getKey()).append(": ") .append(entry.getValue().toList(String.class).stream().collect(Collectors.joining(", "))); } buffer.append(CRLF); rsp.type(MediaType.valueOf("message/http")); rsp.length(buffer.length()); rsp.send(buffer.toString()); }
@Override public void handle(final Request req, final Response rsp) throws Exception { if (!rsp.header(ALLOW).isSet()) { Set<String> allow = new LinkedHashSet<>(); Set<String> methods = new LinkedHashSet<>(Route.METHODS); String path = req.path(); methods.remove(req.method()); for (String method : methods) { routes.stream() .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent()) .forEach(route -> allow.add(route.method())); } rsp.header(ALLOW, Joiner.on(SEP).join(allow)) .length(0) .status(Status.OK); } }
@Override public void handle(final Request req, final Response rsp, final Route.Chain chain) throws Throwable { String path = req.path(); for (Route.Definition router : routes) { // ignore glob route if (!router.glob()) { Optional<Route> ifRoute = router .matches(Route.GET, path, MediaType.all, MediaType.ALL); if (ifRoute.isPresent()) { // route found rsp.length(0); ((RouteImpl) ifRoute.get()).handle(req, rsp, chain); return; } } } // not handled, just call next chain.next(req, rsp); } }
@Override public Response length(final long length) { rsp.length(length); return this; }
/** * Transfer the file at path as an "attachment". Typically, browsers will prompt the user for * download. The <code>Content-Disposition</code> "filename=" parameter (i.e. the one that will * appear in the browser dialog) is set to filename. * * @param filename A file name to use. * @param file A file to use. * @throws Exception If something goes wrong. */ default void download(final String filename, final File file) throws Throwable { length(file.length()); download(filename, new FileInputStream(file)); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String CRLF = "\r\n"; StringBuilder buffer = new StringBuilder("TRACE ").append(req.path()) .append(" ").append(req.protocol()); for (Entry<String, Mutant> entry : req.headers().entrySet()) { buffer.append(CRLF).append(entry.getKey()).append(": ") .append(entry.getValue().toList(String.class).stream().collect(Collectors.joining(", "))); } buffer.append(CRLF); rsp.type(MediaType.valueOf("message/http")); rsp.length(buffer.length()); rsp.send(buffer.toString()); }
@Override public void handle(final Request req, final Response rsp) throws Exception { if (!rsp.header(ALLOW).isSet()) { Set<String> allow = new LinkedHashSet<>(); Set<String> methods = new LinkedHashSet<>(Route.METHODS); String path = req.path(); methods.remove(req.method()); for (String method : methods) { routes.stream() .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent()) .forEach(route -> allow.add(route.method())); } rsp.header(ALLOW, Joiner.on(SEP).join(allow)) .length(0) .status(Status.OK); } }
@Override public void handle(final Request req, final Response rsp, final Route.Chain chain) throws Throwable { String path = req.path(); for (Route.Definition router : routes) { // ignore glob route if (!router.glob()) { Optional<Route> ifRoute = router .matches(Route.GET, path, MediaType.all, MediaType.ALL); if (ifRoute.isPresent()) { // route found rsp.length(0); ((RouteImpl) ifRoute.get()).handle(req, rsp, chain); return; } } } // not handled, just call next chain.next(req, rsp); } }