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>
This commit is contained in:
David Pursehouse 2016-08-13 16:56:20 +09:00
parent 59b96549a6
commit 0b4751e805
1 changed files with 3 additions and 2 deletions

View File

@ -83,7 +83,8 @@ public abstract class LfsProtocolServlet extends HttpServlet {
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();
@ -143,6 +144,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse res)
LfsRequest request = gson.fromJson(r, LfsRequest.class);
String path = req.getPathInfo();
res.setContentType(CONTENTTYPE_VND_GIT_LFS_JSON);
LargeFileRepository repo = null;
try {
repo = getLargeFileRepository(request, path);
@ -150,7 +152,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse res)
res.setStatus(SC_SERVICE_UNAVAILABLE);
} else {
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);