From c32a62cd4abf5529c9e56a1c8140de76c107ff93 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 25 Apr 2018 13:59:52 -0700 Subject: Give info/refs services more control over response Currently, SmartServiceInfoRefs always prints "# service=serviceName" followed by a flush packet in response to an info/refs request, and then hands it off to the specific service class. Printing of "# service=serviceName" is mandated for protocol v0, but not v2. Therefore, the existing code works for protocol v0, but whenever a service that supports protocol v2 receives an info/refs request, it must first determine which protocol version is to be used (depending on, for example, the request and any relevant configuration variables), and then decide if "# service=serviceName" needs to be printed. Create a new method that v2-supporting service classes can override, covering the printing of both "# service=serviceName" and everything that the #advertise method prints. This will be used in a subsequent commit in which UploadPackServlet (and the other classes it uses) is updated to support protocol v2. Change-Id: Ia026b06e96a6b15937514096babd024ef77df1ea Signed-off-by: Jonathan Tan Signed-off-by: Jonathan Nieder --- .../jgit/http/server/SmartServiceInfoRefs.java | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'org.eclipse.jgit.http.server/src/org/eclipse/jgit') 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. + *

+ * 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; -- cgit v1.2.3