]> source.dussan.org Git - jgit.git/commitdiff
FileLfsServlet: Do not pretty print json response 39/113039/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 6 Dec 2017 23:25:50 +0000 (08:25 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Thu, 7 Dec 2017 22:41:15 +0000 (07:41 +0900)
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 <david.pursehouse@gmail.com>
org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java

index f92e638e80aca03ab56c88cb594b64459519016b..69d1a048015d14fc750f05cd342eaeba98f451f1 100644 (file)
@@ -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);
        }
 }
index a8e3c11e27ff66827d6a05ff73ae72463cc94216..b13beb595353adc4b06479f6e0585b91ec025212 100644 (file)
@@ -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();
        }
 }