/** * Check a request for Git-over-HTTP indicators. * * @param req * the current HTTP request that may have been made by Git. * @return true if the request is likely made by a Git client program. */ public static boolean isGitClient(HttpServletRequest req) { return isInfoRefs(req) || isUploadPack(req) || isReceivePack(req); }
/** * Check a request for Git-over-HTTP indicators. * * @param req * the current HTTP request that may have been made by Git. * @return true if the request is likely made by a Git client program. */ public static boolean isGitClient(HttpServletRequest req) { return isInfoRefs(req) || isUploadPack(req) || isReceivePack(req); }
/** * Get the response Content-Type a client expects for the request. * <p> * This method should only be invoked if * {@link #isGitClient(HttpServletRequest)} is true. * * @param req * current request. * @return the Content-Type the client expects. * @throws IllegalArgumentException * the request is not a Git client request. See * {@link #isGitClient(HttpServletRequest)}. */ public static String getResponseContentType(HttpServletRequest req) { if (isInfoRefs(req)) return infoRefsResultType(req.getParameter("service")); else if (isUploadPack(req)) return UPLOAD_PACK_RESULT_TYPE; else if (isReceivePack(req)) return RECEIVE_PACK_RESULT_TYPE; else throw new IllegalArgumentException(); }
/** * Get the response Content-Type a client expects for the request. * <p> * This method should only be invoked if * {@link #isGitClient(HttpServletRequest)} is true. * * @param req * current request. * @return the Content-Type the client expects. * @throws IllegalArgumentException * the request is not a Git client request. See * {@link #isGitClient(HttpServletRequest)}. */ public static String getResponseContentType(HttpServletRequest req) { if (isInfoRefs(req)) return infoRefsResultType(req.getParameter("service")); else if (isUploadPack(req)) return UPLOAD_PACK_RESULT_TYPE; else if (isReceivePack(req)) return RECEIVE_PACK_RESULT_TYPE; else throw new IllegalArgumentException(); }
@Sessional @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; try { if (GitSmartHttpTools.isInfoRefs(httpRequest)) { if (oneDev.isReady()) processRefs(httpRequest, httpResponse); else throw new GitException("Server is not ready"); } else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) { if (oneDev.isReady()) processPacks(httpRequest, httpResponse); else throw new GitException("Server is not ready"); } else { chain.doFilter(request, response); } } catch (GitException|InterruptedException|ExecutionException e) { logger.error("Error serving git request", e); GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
} else if (isUploadPack(req)) { sendUploadPackError(req, res, textForGit); } else if (isReceivePack(req)) { sendReceivePackError(req, res, textForGit); } else {
} else if (isUploadPack(req)) { sendUploadPackError(req, res, textForGit); } else if (isReceivePack(req)) { sendReceivePackError(req, res, textForGit); } else {