本文整理汇总了Java中org.kohsuke.stapler.StaplerRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java StaplerRequest.getHeader方法的具体用法?Java StaplerRequest.getHeader怎么用?Java StaplerRequest.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kohsuke.stapler.StaplerRequest
的用法示例。
在下文中一共展示了StaplerRequest.getHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import org.kohsuke.stapler.StaplerRequest; //导入方法依赖的package包/类
public HttpResponse doPost(StaplerRequest request) throws IOException {
if (!request.getMethod().equals("POST")) {
return HttpResponses
.error(HttpServletResponse.SC_BAD_REQUEST,
"Only POST requests are supported, this was a " + request.getMethod() + " request");
}
if (!"application/json".equals(request.getContentType())) {
return HttpResponses
.error(HttpServletResponse.SC_BAD_REQUEST,
"Only application/json content is supported, this was " + request.getContentType());
}
String type = request.getHeader("X-Gitea-Event");
if (StringUtils.isBlank(type)) {
return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST,
"Expecting a Gitea event, missing expected X-Gitea-Event header");
}
String origin = SCMEvent.originOf(request);
boolean processed = false;
for (GiteaWebhookHandler<?, ?> h : ExtensionList.lookup(GiteaWebhookHandler.class)) {
if (h.matches(type)) {
h.process(request.getInputStream(), origin);
processed = true;
}
}
return HttpResponses.plainText(processed ? "Processed" : "Ignored");
}
示例2: generateResponse
import org.kohsuke.stapler.StaplerRequest; //导入方法依赖的package包/类
/**
* TO DO
* @param req
* @param rsp
* @param node
* @throws IOException
* @throws ServletException
*/
@Override
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
// Check if the latest badge is already cached
String v = req.getHeader("If-None-Match");
if (etag.equals(v)) {
rsp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
rsp.setHeader("ETag", etag);
rsp.setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
rsp.setHeader("Cache-Control", "no-cache, private");
rsp.setHeader("Content-Type", "image/svg+xml;charset=utf-8");
rsp.setHeader("Content-Length", length);
rsp.getOutputStream().write(payload);
}