本文整理匯總了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);
}