From 74bfdcd555a6f737c58daa4622e75108dba5e21f Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 Dec 2017 08:25:50 +0900 Subject: [PATCH 1/3] FileLfsServlet: Do not pretty print json response Pretty printing the response is useful for human readers, but most (if not all) of the time, the response will be read by programs. Remove it to avoid the additional overhead of the formatting and extra bytes in the response. Adjust the test accordingly. Note that LfsProtocolServlet already doesn't use pretty printing, so this change makes FileLfsServlet's behavior consistent. In fact, both classes now have duplicate Gson handling; this will be cleaned up in a separate change. Change-Id: I113a23403f9222f16e2c0ddf39461398b721d064 Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java | 4 ++-- .../org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java index f92e638e8..69d1a0480 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java @@ -129,7 +129,7 @@ public class DownloadTest extends LfsServerTest { long start = System.nanoTime(); long len = getContent(id, f2); System.out.println( - MessageFormat.format("dowloaded 10 MiB random data in {0}ms", + MessageFormat.format("downloaded 10 MiB random data in {0}ms", (System.nanoTime() - start) / 1e6)); assertEquals(expectedLen, len); FileUtils.delete(f.toFile(), FileUtils.RETRY); @@ -138,7 +138,7 @@ public class DownloadTest extends LfsServerTest { @SuppressWarnings("boxing") private String formatErrorMessage(int status, String message) { - return String.format("Status: %d {\n \"message\": \"%s\"\n}", status, + return String.format("Status: %d {\"message\":\"%s\"}", status, message); } } diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java index a8e3c11e2..b13beb595 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java @@ -211,10 +211,9 @@ public class FileLfsServlet extends HttpServlet { } private static Gson createGson() { - GsonBuilder gb = new GsonBuilder() - .setFieldNamingPolicy( - FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .setPrettyPrinting().disableHtmlEscaping(); - return gb.create(); + return new GsonBuilder() + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) + .disableHtmlEscaping() + .create(); } } From 53a11cb1d115eb58db1f1d22dc29a50368153205 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 Dec 2017 09:51:56 +0900 Subject: [PATCH 2/3] InvalidLongObjectIdException: Fix formatting of message The message is formatted as: Invalid id: : abcde... but should be: Invalid id: abcde... Change-Id: Ie15cacdcf2f168edaee262e6cf8061ebfe9d998d Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java | 2 +- .../eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java index 69d1a0480..64cecd8cb 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java @@ -97,7 +97,7 @@ public class DownloadTest extends LfsServerTest { getContent(id, f); fail("expected RuntimeException"); } catch (RuntimeException e) { - String error = String.format("Invalid id: : %s", id); + String error = String.format("Invalid id: %s", id); assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error), e.getMessage()); } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java index 1f6e2d174..44ac317a1 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java @@ -80,7 +80,7 @@ public class InvalidLongObjectIdException extends IllegalArgumentException { private static String asAscii(byte[] bytes, int offset, int length) { try { - return ": " + new String(bytes, offset, length, "US-ASCII"); //$NON-NLS-1$ //$NON-NLS-2$ + return new String(bytes, offset, length, "US-ASCII"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e2) { return ""; //$NON-NLS-1$ } catch (StringIndexOutOfBoundsException e2) { From deb68cfb4ae602d4e49b19fffa55bdf2f727ed42 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 Dec 2017 10:18:21 +0900 Subject: [PATCH 3/3] LfsServerText: Fix formatting of invalidPathInfo message The message is formatted as: Invalid pathInfo '/abc' does not match '/{SHA-256}' but should be: Invalid pathInfo: '/abc' does not match '/{SHA-256}' (i.e. including a colon) to be consistent with other messages. Change-Id: Ic38aa7d33dd02d7954b95c331a73919a90c69991 Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java | 2 +- .../eclipse/jgit/lfs/server/internal/LfsServerText.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java index 64cecd8cb..303d8056d 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java @@ -81,7 +81,7 @@ public class DownloadTest extends LfsServerTest { fail("expected RuntimeException"); } catch (RuntimeException e) { String error = String.format( - "Invalid pathInfo '/%s' does not match '/{SHA-256}'", id); + "Invalid pathInfo: '/%s' does not match '/{SHA-256}'", id); assertEquals(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error), e.getMessage()); } diff --git a/org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties b/org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties index b2b487eef..659714528 100644 --- a/org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties +++ b/org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties @@ -1,5 +1,5 @@ failedToCalcSignature=Failed to calculate a request signature: {0} -invalidPathInfo=Invalid pathInfo ''{0}'' does not match ''/'{'SHA-256'}''' +invalidPathInfo=Invalid pathInfo: ''{0}'' does not match ''/'{'SHA-256'}''' objectNotFound=Object ''{0}'' not found undefinedS3AccessKey=S3 configuration: 'accessKey' is undefined undefinedS3Bucket=S3 configuration: 'bucket' is undefined