diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2018-02-28 14:36:44 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2018-06-04 21:59:20 -0700 |
commit | f516c1df9d18ff9aaba1dd5668db1776d42dd2bb (patch) | |
tree | 464ad8af58c01d1226785bc09c83d3a4fe2498af /org.eclipse.jgit.http.server/src | |
parent | c32a62cd4abf5529c9e56a1c8140de76c107ff93 (diff) | |
download | jgit-f516c1df9d18ff9aaba1dd5668db1776d42dd2bb.tar.gz jgit-f516c1df9d18ff9aaba1dd5668db1776d42dd2bb.zip |
Add protocol v2 support in http
Teach UploadPack to support protocol v2 with non-bidirectional pipes,
and add support to the HTTP protocol for v2. This is only activated if
the repository's config has "protocol.version" equal to 2.
Change-Id: I093a14acd2c3850b8b98e14936a716958f35a848
Helped-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.http.server/src')
2 files changed, 32 insertions, 3 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index 3e9c1fefac..ca6b749e75 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java @@ -76,6 +76,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.InternalHttpServerGlue; +import org.eclipse.jgit.transport.PacketLineOut; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; import org.eclipse.jgit.transport.ServiceMayNotContinueException; import org.eclipse.jgit.transport.UploadPack; @@ -117,6 +118,25 @@ class UploadPackServlet extends HttpServlet { up.setBiDirectionalPipe(false); up.sendAdvertisedRefs(pck); } finally { + // TODO(jonathantanmy): Move responsibility for closing the + // RevWalk to UploadPack, either by making it AutoCloseable + // or by making sendAdvertisedRefs clean up after itself. + up.getRevWalk().close(); + } + } + + @Override + protected void respond(HttpServletRequest req, + PacketLineOut pckOut, String serviceName) throws IOException, + ServiceNotEnabledException, ServiceNotAuthorizedException { + UploadPack up = (UploadPack) req.getAttribute(ATTRIBUTE_HANDLER); + try { + up.setBiDirectionalPipe(false); + up.sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut), serviceName); + } finally { + // TODO(jonathantanmy): Move responsibility for closing the + // RevWalk to UploadPack, either by making it AutoCloseable + // or by making sendAdvertisedRefs clean up after itself. up.getRevWalk().close(); } } diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java index 30edc15166..a69fab0afd 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.http.server.resolver; +import java.util.Arrays; + import javax.servlet.http.HttpServletRequest; import org.eclipse.jgit.lib.Config; @@ -73,9 +75,16 @@ public class DefaultUploadPackFactory implements @Override public UploadPack create(HttpServletRequest req, Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { - if (db.getConfig().get(ServiceConfig::new).enabled) - return new UploadPack(db); - else + if (db.getConfig().get(ServiceConfig::new).enabled) { + UploadPack up = new UploadPack(db); + String header = req.getHeader("Git-Protocol"); //$NON-NLS-1$ + if (header != null) { + String[] params = header.split(":"); //$NON-NLS-1$ + up.setExtraParameters(Arrays.asList(params)); + } + return up; + } else { throw new ServiceNotEnabledException(); + } } } |