FilterChain chain) throws IOException, ServletException {
boolean isGet =
"GET".equalsIgnoreCase(((HttpServletRequest) request).getMethod());
ReceiveCommits rc = (ReceiveCommits) request.getAttribute(ATT_RC);
ReceivePack rp = rc.getReceivePack();
ProjectControl pc = (ProjectControl) request.getAttribute(ATT_CONTROL);
Project.NameKey projectName = pc.getProject().getNameKey();
if (!pc.canRunReceivePack()) {
GitSmartHttpTools.sendError((HttpServletRequest) request,
(HttpServletResponse) response, HttpServletResponse.SC_FORBIDDEN,
"receive-pack not permitted on this server");
return;
}
final Capable s = rc.canUpload();
if (s != Capable.OK) {
GitSmartHttpTools.sendError((HttpServletRequest) request,
(HttpServletResponse) response, HttpServletResponse.SC_FORBIDDEN,
"\n" + s.getMessage());
return;
}
if (!rp.isCheckReferencedObjectsAreReachable()) {
if (isGet) {
rc.advertiseHistory();
}
chain.doFilter(request, response);
return;
}
if (!(pc.getCurrentUser() instanceof IdentifiedUser)) {
chain.doFilter(request, response);
return;
}
AdvertisedObjectsCacheKey cacheKey = new AdvertisedObjectsCacheKey(
((IdentifiedUser) pc.getCurrentUser()).getAccountId(),
projectName);
if (isGet) {
rc.advertiseHistory();
cache.invalidate(cacheKey);
} else {
Set<ObjectId> ids = cache.getIfPresent(cacheKey);
if (ids != null) {
rp.getAdvertisedObjects().addAll(ids);
cache.invalidate(cacheKey);
}
}
chain.doFilter(request, response);
if (isGet) {
cache.put(cacheKey, Collections.unmodifiableSet(
new HashSet<ObjectId>(rp.getAdvertisedObjects())));
}
}