浏览代码

Fix error handling in RepositoryFilter

The filter did not correctly match smart HTTP client requests,
so it always fell back on HTTP status codes for errors. This
usually causes a smart client to retry a dumb request, which
is not what the server wants.

Change-Id: I42592378dc42fbe308ef30a2923786c690f668a9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
tags/v1.0.0.201106011211-rc3
Shawn O. Pearce 13 年前
父节点
当前提交
de16d5e8f9
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6
    3
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java

+ 6
- 3
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java 查看文件

@@ -154,10 +154,8 @@ public class RepositoryFilter implements Filter {
static void sendError(int statusCode, HttpServletRequest req,
HttpServletResponse rsp) throws IOException {
String svc = req.getParameter("service");
String accept = req.getHeader(HDR_ACCEPT);

if (svc != null && svc.startsWith("git-") && accept != null
&& accept.contains("application/x-" + svc + "-advertisement")) {
if (req.getRequestURI().endsWith("/info/refs") && isService(svc)) {
// Smart HTTP service request, use an ERR response.
rsp.setContentType("application/x-" + svc + "-advertisement");

@@ -170,6 +168,7 @@ public class RepositoryFilter implements Filter {
return;
}

String accept = req.getHeader(HDR_ACCEPT);
if (accept != null && accept.contains(UploadPackServlet.RSP_TYPE)) {
// An upload-pack wants ACK or NAK, return ERR
// and the client will print this instead.
@@ -188,6 +187,10 @@ public class RepositoryFilter implements Filter {
rsp.sendError(statusCode);
}

private static boolean isService(String svc) {
return "git-upload-pack".equals(svc) || "git-receive-pack".equals(svc);
}

private static String translate(int statusCode) {
switch (statusCode) {
case SC_NOT_FOUND:

正在加载...
取消
保存