Return meaningful message when LFS plugin is not configured
When lfs.plugin setting is not configured in gerrit.config LFS client returns with server error: Server error: http://server/gerrit/repo.git/info/lfs/objects/batch from HTTP 501 It would be easier to fix it when error would be more specific e.g.: No LFS plugin is configured to handle LFS requests. Change-Id: I0f4418a758e5e3cec5f058b73f35ce8136f7c8e0 Signed-off-by: Jacek Centkowski <jcentkowski@collab.net>
This commit is contained in:
committed by
Jacek Centkowski
parent
bc425ff53b
commit
92884c387c
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.httpd.plugins;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED;
|
||||
|
||||
import com.google.gerrit.extensions.registration.RegistrationHandle;
|
||||
@@ -31,7 +32,10 @@ import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -56,6 +60,11 @@ public class LfsPluginServlet extends HttpServlet
|
||||
public static final String URL_REGEX =
|
||||
"^(?:/a)?(?:/p/|/)(.+)(?:/info/lfs/objects/batch)$";
|
||||
|
||||
private static final String CONTENTTYPE_VND_GIT_LFS_JSON =
|
||||
"application/vnd.git-lfs+json; charset=utf-8";
|
||||
private static final String MESSAGE_LFS_NOT_CONFIGURED =
|
||||
"{\"message\":\"No LFS plugin is configured to handle LFS requests.\"}";
|
||||
|
||||
private List<Plugin> pending = new ArrayList<>();
|
||||
private final String pluginName;
|
||||
private final FilterChain chain;
|
||||
@@ -79,8 +88,7 @@ public class LfsPluginServlet extends HttpServlet
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res)
|
||||
throws ServletException, IOException {
|
||||
if (filter.get() == null) {
|
||||
CacheHeaders.setNotCacheable(res);
|
||||
res.sendError(SC_NOT_IMPLEMENTED);
|
||||
responseLfsNotConfigured(res);
|
||||
return;
|
||||
}
|
||||
filter.get().doFilter(req, res, chain);
|
||||
@@ -110,6 +118,17 @@ public class LfsPluginServlet extends HttpServlet
|
||||
install(newPlugin);
|
||||
}
|
||||
|
||||
private void responseLfsNotConfigured(HttpServletResponse res)
|
||||
throws IOException {
|
||||
CacheHeaders.setNotCacheable(res);
|
||||
res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
|
||||
res.setStatus(SC_NOT_IMPLEMENTED);
|
||||
Writer w = new BufferedWriter(
|
||||
new OutputStreamWriter(res.getOutputStream(), UTF_8));
|
||||
w.write(MESSAGE_LFS_NOT_CONFIGURED);
|
||||
w.flush();
|
||||
}
|
||||
|
||||
private void install(Plugin plugin) {
|
||||
if (!plugin.getName().equals(pluginName)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user