summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2018-04-25 13:59:52 -0700
committerJonathan Nieder <jrn@google.com>2018-06-04 21:54:25 -0700
commitc32a62cd4abf5529c9e56a1c8140de76c107ff93 (patch)
treecf8450fe8261b0652130529a5288cde60aeb64cd /org.eclipse.jgit.http.server/src/org/eclipse/jgit
parent36a8c2106983d9070a2c67961f7945db76403776 (diff)
downloadjgit-c32a62cd4abf5529c9e56a1c8140de76c107ff93.tar.gz
jgit-c32a62cd4abf5529c9e56a1c8140de76c107ff93.zip
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 <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.http.server/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java35
1 files changed, 32 insertions, 3 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;