Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder2018-06-05 05:22:24 +0000
committerJonathan Nieder2018-06-05 05:22:24 +0000
commit903432ef4d6505d91eb76d09b4ded0a554f05e90 (patch)
treec1048c542fdf42053da8de7d6048d9da4b74b0d3 /org.eclipse.jgit.http.server
parent61e2414ef7f42759a9834c668f8059a098b71965 (diff)
parent7dbd2bfe7e0598097cf35aedd700d86b468bec7d (diff)
downloadjgit-903432ef4d6505d91eb76d09b4ded0a554f05e90.tar.gz
jgit-903432ef4d6505d91eb76d09b4ded0a554f05e90.tar.xz
jgit-903432ef4d6505d91eb76d09b4ded0a554f05e90.zip
Merge branch 'stable-5.0'
* stable-5.0: Teach UploadPack "filter" in protocol v2 fetch Refactor test of capabilities output Refactor v2 advertisement into own function Refactor parsing of "filter" into its own method Disallow unknown args to "fetch" in protocol v2 Teach UploadPack shallow fetch in protocol v2 Refactor unshallowCommits to local variable Add protocol v2 support in http Give info/refs services more control over response Change-Id: I1683902222e076e1091795e94790a264550afb7b Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java35
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java20
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java15
3 files changed, 64 insertions, 6 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
index 92009c5731..195dff9613 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
@@ -133,9 +133,7 @@ abstract class SmartServiceInfoRefs implements Filter {
res.setContentType(infoRefsResultType(svc));
final PacketLineOut out = new PacketLineOut(buf);
- out.writeString("# service=" + svc + "\n");
- out.end();
- advertise(req, new PacketLineOutRefAdvertiser(out));
+ respond(req, out, svc);
buf.close();
} catch (ServiceNotAuthorizedException e) {
res.sendError(SC_UNAUTHORIZED, e.getMessage());
@@ -178,6 +176,37 @@ abstract class SmartServiceInfoRefs implements Filter {
PacketLineOutRefAdvertiser pck) throws IOException,
ServiceNotEnabledException, ServiceNotAuthorizedException;
+ /**
+ * Writes the appropriate response to an info/refs request received by
+ * a smart service. In protocol v0, this starts with "#
+ * service=serviceName" followed by a flush packet, but this is not
+ * necessarily the case in other protocol versions.
+ * <p>
+ * The default implementation writes "# service=serviceName" and a
+ * flush packet, then calls {@link #advertise}. Subclasses should
+ * override this method if they support protocol versions other than
+ * protocol v0.
+ *
+ * @param req
+ * request
+ * @param pckOut
+ * destination of response
+ * @param serviceName
+ * service name to be written out in protocol v0; may or may
+ * not be used in other versions
+ * @throws IOException
+ * @throws ServiceNotEnabledException
+ * @throws ServiceNotAuthorizedException
+ */
+ protected void respond(HttpServletRequest req,
+ PacketLineOut pckOut, String serviceName)
+ throws IOException, ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ pckOut.writeString("# service=" + svc + '\n'); //$NON-NLS-1$
+ pckOut.end();
+ advertise(req, new PacketLineOutRefAdvertiser(pckOut));
+ }
+
private class Chain implements FilterChain {
private int filterIdx;
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();
+ }
}
}

Back to the top