From 4a984e20332a765a81cadeaa4875b228ebf290fb Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Thu, 30 Apr 2015 12:43:46 -0700 Subject: Support agent= capability in wire protocol Since git-core ff5effd (v1.7.12.1) the native wire protocol transmits the server and client implementation and version strings using capability "agent=git/1.7.12.1" or similar. Support this in JGit and hang the implementation data off UploadPack and ReceivePack. On HTTP transports default to the User-Agent HTTP header until the client overrides this with the optional capability string in the first line. Extract the user agent string into a UserAgent class under transport where it can be specified to a different value if the application's build process has broken the Implementation-Version header in the JGit package. Change-Id: Icfc6524d84a787386d1786310b421b2f92ae9e65 --- .../src/org/eclipse/jgit/http/server/ReceivePackServlet.java | 4 ++++ .../src/org/eclipse/jgit/http/server/UploadPackServlet.java | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'org.eclipse.jgit.http.server') diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java index d1c258047b..a8e312d3f0 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java @@ -76,6 +76,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.errors.UnpackException; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.InternalHttpServerGlue; import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; import org.eclipse.jgit.transport.resolver.ReceivePackFactory; @@ -100,6 +101,9 @@ class ReceivePackServlet extends HttpServlet { throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { ReceivePack rp = receivePackFactory.create(req, db); + InternalHttpServerGlue.setPeerUserAgent( + rp, + req.getHeader(HDR_USER_AGENT)); req.setAttribute(ATTRIBUTE_HANDLER, rp); } 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 c5272b55eb..7aefcbd809 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 @@ -74,6 +74,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.InternalHttpServerGlue; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.UploadPackInternalServerErrorException; @@ -100,6 +101,9 @@ class UploadPackServlet extends HttpServlet { throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { UploadPack up = uploadPackFactory.create(req, db); + InternalHttpServerGlue.setPeerUserAgent( + up, + req.getHeader(HDR_USER_AGENT)); req.setAttribute(ATTRIBUTE_HANDLER, up); } -- cgit v1.2.3