in src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java [110:152]
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (request instanceof HttpServletRequest) {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
if ("1".equals(req.getParameter("go-get"))) {
boolean authenticated = AUTHENTICATED_REQ.matcher(req.getServletPath()).matches();
// For authenticated requests remove prefix "/a" to get project name.
String path =
authenticated ? req.getServletPath().replaceFirst("^/a/", "/") : req.getServletPath();
// Because Gerrit allows for arbitrary-depth project names
// (that is, both "a" and "a/b/c" are both legal), we are going
// to find the most specific such project that matches the path.
//
// For example, assume that we have the following projects:
// a
// a/b
// 1. If the requested path is "a", then project "a" would be chosen.
// 2. If the requested path is "a/b", then project "a/b" would be chosen.
// 3. If the requested path is "a/c", then project "a" would be chosen.
// 4. If the requested path is "a/b/c/d", then project "a/b" would be chosen.
// 5. If the requested path is "x/y/z", then this will fail with a 404 error.
String existent = getLongestMatch(getProjectName(path));
byte[] toSend = PAGE_404.getBytes();
rsp.setStatus(404);
if (!Strings.isNullOrEmpty(existent)) {
toSend = PAGE_200.replace(CONTENT_PLH, getContent(existent, authenticated)).getBytes();
rsp.setStatus(200);
}
CacheHeaders.setNotCacheable(rsp);
rsp.setContentType("text/html");
rsp.setCharacterEncoding(HtmlDomUtil.ENC.name());
rsp.setContentLength(toSend.length);
try (OutputStream out = rsp.getOutputStream()) {
out.write(toSend);
}
} else {
chain.doFilter(request, response);
}
} else {
chain.doFilter(request, response);
}
}