@Override public Response header(final String name, final Object... values) { rsp.header(name, values); return this; }
@Override public void setResponseHeader(final String name, final String value) { rsp.header(name, value); }
@Override public Response header(final String name, final Iterable<Object> values) { rsp.header(name, values); return this; }
@Override public Response header(final String name, final Object value) { rsp.header(name, value); return this; }
@Override public Mutant header(final String name) { return rsp.header(name); }
@Override public void setResponseHeader(String name, String value) { rsp.header(name, value); }
/** * Sets a response header with the given name and value. If the header had already been set, * the new value overwrites the previous one. * * @param name Header's name. * @param values Header's value. * @return This response. */ @Nonnull default Response header(final String name, final Object... values) { return header(name, ImmutableList.builder().add(values).build()); }
@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); } }
private void cors(final Cors cors, final Request req, final Response rsp, final String origin) throws Exception { if (cors.allowOrigin(origin)) { log.debug("allowed origin: {}", origin); if (preflight(req)) { log.debug("handling preflight for: {}", origin); preflight(cors, req, rsp, origin); } else { log.debug("handling simple cors for: {}", origin); if ("null".equals(origin)) { rsp.header(AC_ALLOW_ORIGIN, ANY_ORIGIN); } else { rsp.header(AC_ALLOW_ORIGIN, origin); if (!cors.anyOrigin()) { rsp.header("Vary", ORIGIN); } if (cors.credentials()) { rsp.header(AC_ALLOW_CREDENTIALS, true); } if (!cors.exposedHeaders().isEmpty()) { rsp.header(AC_EXPOSE_HEADERS, join(cors.exposedHeaders())); } } } } }
@Override public void handle(final Request req, final Response rsp) throws Throwable { rsp.status(Status.OK) .type(MediaType.plain) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send("pong"); ; }
sb.append(status); sb.append(SP); sb.append(ersp.header(CONTENT_LENGTH).value(DASH)); if (extended) { sb.append(SP);
@Override public void handle(final Request req, final Response rsp) throws Throwable { Object data; Status status; if (threadDump == null) { data = "Sorry your runtime environment does not allow to dump threads."; status = Status.NOT_IMPLEMENTED; } else { final ByteArrayOutputStream output = new ByteArrayOutputStream(); threadDump.dump(output); data = output.toByteArray(); status = Status.OK; } rsp.type(MediaType.plain) .status(status) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send(data); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { HealthCheckRegistry registry = req.require(HealthCheckRegistry.class); SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> { SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name)); return set; }).orElseGet(() -> registry.runHealthChecks()); final Status status; if (checks.isEmpty()) { status = Status.NOT_IMPLEMENTED; } else { status = checks.values().stream() .filter(it -> !it.isHealthy()) .findFirst() .map(it -> Status.SERVER_ERROR) .orElse(Status.OK); } rsp.status(status) .header("Cache-Control", "must-revalidate,no-cache,no-store") .send(checks); }
@Override public Response header(final String name, final Object value) { rsp.header(name, value); return this; }
@Override public Mutant header(final String name) { return rsp.header(name); }
@Override public Response header(final String name, final Object... values) { rsp.header(name, values); return this; }
/** * Sets a response header with the given name and value. If the header had already been set, * the new value overwrites the previous one. * * @param name Header's name. * @param values Header's value. * @return This response. */ @Nonnull default Response header(final String name, final Object... values) { return header(name, ImmutableList.builder().add(values).build()); }