diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java index 7d2efd26c..7b1a67007 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java @@ -82,40 +82,57 @@ public abstract class LfsProtocolServlet extends HttpServlet { /** * Get the large file repository * - * @return the large file repository storing large files + * @param request + * the request + * @param path + * the path + * + * @return the large file repository storing large files or null if the + * request is not supported. */ - protected abstract LargeFileRepository getLargeFileRepository(); + protected abstract LargeFileRepository getLargeFileRepository( + LfsRequest request, String path); + + /** LFS request. */ + protected static class LfsRequest { + private String operation; + + private List objects; + + /** + * Get the LFS operation. + * + * @return the operation + */ + public String getOperation() { + return operation; + } + } @Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - res.setStatus(SC_OK); - res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON); - Writer w = new BufferedWriter( new OutputStreamWriter(res.getOutputStream(), UTF_8)); Reader r = new BufferedReader(new InputStreamReader(req.getInputStream(), UTF_8)); LfsRequest request = gson.fromJson(r, LfsRequest.class); + String path = req.getPathInfo(); - LargeFileRepository repo = getLargeFileRepository(); + LargeFileRepository repo = getLargeFileRepository(request, path); if (repo == null) { res.setStatus(SC_SERVICE_UNAVAILABLE); return; } + res.setStatus(SC_OK); + res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON); TransferHandler handler = TransferHandler .forOperation(request.operation, repo, request.objects); gson.toJson(handler.process(), w); w.flush(); } - private static class LfsRequest { - String operation; - - List objects; - } - private static Gson createGson() { GsonBuilder gb = new GsonBuilder() .setFieldNamingPolicy( diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/LfsStore.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/LfsStore.java index 00bea86c4..c4d95481f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/LfsStore.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/LfsStore.java @@ -253,10 +253,10 @@ protected void run() throws Exception { private static final long serialVersionUID = 1L; @Override - protected LargeFileRepository getLargeFileRepository() { + protected LargeFileRepository getLargeFileRepository( + LfsRequest request, String path) { return repository; } - }; app.addServlet(new ServletHolder(protocol), PROTOCOL_PATH);