Browse Source

LfsProtocolServlet: Always set the Content-Type header on response

If the Content-Type is not set on error responses, the git-lfs client
does not read the body which contains the error message, and instead
just displays a generic error message.

Also set the charset on the Content-Type header.

Change-Id: I88e6f07f20b622a670e7c5063145dffb8b630aee
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-4.5
David Pursehouse 8 years ago
parent
commit
0b4751e805
  1. 5
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java

5
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java

@ -83,7 +83,8 @@ public abstract class LfsProtocolServlet extends HttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String CONTENTTYPE_VND_GIT_LFS_JSON = "application/vnd.git-lfs+json"; //$NON-NLS-1$ private static final String CONTENTTYPE_VND_GIT_LFS_JSON =
"application/vnd.git-lfs+json; charset=utf-8"; //$NON-NLS-1$
private Gson gson = createGson(); private Gson gson = createGson();
@ -143,6 +144,7 @@ public abstract class LfsProtocolServlet extends HttpServlet {
LfsRequest request = gson.fromJson(r, LfsRequest.class); LfsRequest request = gson.fromJson(r, LfsRequest.class);
String path = req.getPathInfo(); String path = req.getPathInfo();
res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
LargeFileRepository repo = null; LargeFileRepository repo = null;
try { try {
repo = getLargeFileRepository(request, path); repo = getLargeFileRepository(request, path);
@ -150,7 +152,6 @@ public abstract class LfsProtocolServlet extends HttpServlet {
res.setStatus(SC_SERVICE_UNAVAILABLE); res.setStatus(SC_SERVICE_UNAVAILABLE);
} else { } else {
res.setStatus(SC_OK); res.setStatus(SC_OK);
res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
TransferHandler handler = TransferHandler TransferHandler handler = TransferHandler
.forOperation(request.operation, repo, request.objects); .forOperation(request.operation, repo, request.objects);
gson.toJson(handler.process(), w); gson.toJson(handler.process(), w);

Loading…
Cancel
Save