use of org.kohsuke.stapler.StaplerResponse in project blueocean-plugin by jenkinsci.
the class ApiHead method getDynamic.
/**
* Exposes all {@link ApiRoutable}s to URL space.
*
* @param route current URL route handled by ApiHead
* @return {@link ApiRoutable} object
*/
public ApiRoutable getDynamic(String route) {
setApis();
StaplerRequest request = Stapler.getCurrentRequest();
String m = request.getMethod();
if (m.equalsIgnoreCase("POST") || m.equalsIgnoreCase("PUT") || m.equalsIgnoreCase("PATCH")) {
String header = request.getHeader("Content-Type");
if (header == null || !header.contains("application/json")) {
throw new ServiceException(415, "Content-Type: application/json required");
}
}
ApiRoutable apiRoutable = apis.get(route);
// JENKINS-46025 - Avoid caching REST API responses for IE
StaplerResponse response = Stapler.getCurrentResponse();
if (response != null && !response.containsHeader("Cache-Control")) {
response.setHeader("Cache-Control", "no-cache, no-store, no-transform");
}
return apiRoutable;
}
use of org.kohsuke.stapler.StaplerResponse in project configuration-as-code-plugin by jenkinsci.
the class ConfigurationAsCode method doCheck.
@RequirePOST
@Restricted(NoExternalUse.class)
public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final Map<Source, String> issues = checkWith(YamlSource.of(req));
res.setContentType("application/json");
final JSONArray warnings = new JSONArray();
issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate("warning", e.getValue())).forEach(warnings::add);
warnings.write(res.getWriter());
}
Aggregations