From cba68ffda434df57b774e18ddb2a80c205ffbe1f Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Thu, 17 Sep 2020 10:39:09 +0200 Subject: Revert "Fix content-types" --- .../server/http/SessionContentReadResponse.java | 34 +--------------- configserver/src/main/resources/mime.types | 20 --------- .../apps/content/foo/bar/file-without-extension | 1 - .../src/test/apps/content/foo/bar/test.jar | 1 - .../src/test/apps/content/foo/bar/test.txt | 1 + configserver/src/test/apps/content/foo/test1.json | 1 - configserver/src/test/apps/content/foo/test1.txt | 1 + .../config/server/http/ContentHandlerTestBase.java | 47 +++++++++------------- 8 files changed, 23 insertions(+), 83 deletions(-) delete mode 100644 configserver/src/main/resources/mime.types delete mode 100644 configserver/src/test/apps/content/foo/bar/file-without-extension delete mode 100644 configserver/src/test/apps/content/foo/bar/test.jar create mode 100644 configserver/src/test/apps/content/foo/bar/test.txt delete mode 100644 configserver/src/test/apps/content/foo/test1.json create mode 100644 configserver/src/test/apps/content/foo/test1.txt (limited to 'configserver/src') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionContentReadResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionContentReadResponse.java index f122768672d..a1a41cc0472 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionContentReadResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionContentReadResponse.java @@ -7,12 +7,6 @@ import com.yahoo.container.jdisc.HttpResponse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; import static com.yahoo.jdisc.http.HttpResponse.Status.OK; @@ -23,8 +17,6 @@ import static com.yahoo.jdisc.http.HttpResponse.Status.OK; */ public class SessionContentReadResponse extends HttpResponse { - private static final Map contentTypeByExtension = loadContentTypeByExtension(); - private final ApplicationFile file; public SessionContentReadResponse(ApplicationFile file) { @@ -41,31 +33,7 @@ public class SessionContentReadResponse extends HttpResponse { @Override public String getContentType() { - String filename = file.getPath().getName(); - int lastDotIndex = filename.lastIndexOf('.'); - if (lastDotIndex >= 0) { - String contentType = contentTypeByExtension.get(filename.substring(lastDotIndex + 1)); - if (contentType != null) return contentType; - } - return DEFAULT_MIME_TYPE; - } - - private static Map loadContentTypeByExtension() { - try { - Pattern whitespace = Pattern.compile("\\s"); - Map map = new HashMap<>(); - for (String line : Files.readAllLines(Paths.get("src/main/resources/mime.types"))) { - if (line.isEmpty() || line.charAt(0) == '#') continue; - - String[] parts = whitespace.split(line); - for (int i = 1; i < parts.length; i++) - map.putIfAbsent(parts[i], parts[0]); - } - - return map; - } catch (IOException e) { - throw new UncheckedIOException(e); - } + return HttpResponse.DEFAULT_MIME_TYPE; } } diff --git a/configserver/src/main/resources/mime.types b/configserver/src/main/resources/mime.types deleted file mode 100644 index f6672f7738d..00000000000 --- a/configserver/src/main/resources/mime.types +++ /dev/null @@ -1,20 +0,0 @@ -application/xml xml -application/java-archive jar -application/javascript js -application/json json - -text/html html -text/css css - -font/collection ttc -font/otf otf -font/ttf ttf -font/woff woff -font/woff2 woff2 - -image/x-icon ico -image/gif gif -image/jpeg jpg jpeg -image/png png -image/svg+xml svg -image/tiff tiff tif diff --git a/configserver/src/test/apps/content/foo/bar/file-without-extension b/configserver/src/test/apps/content/foo/bar/file-without-extension deleted file mode 100644 index 6b584e8ece5..00000000000 --- a/configserver/src/test/apps/content/foo/bar/file-without-extension +++ /dev/null @@ -1 +0,0 @@ -content \ No newline at end of file diff --git a/configserver/src/test/apps/content/foo/bar/test.jar b/configserver/src/test/apps/content/foo/bar/test.jar deleted file mode 100644 index 401a9f6e542..00000000000 --- a/configserver/src/test/apps/content/foo/bar/test.jar +++ /dev/null @@ -1 +0,0 @@ -bim diff --git a/configserver/src/test/apps/content/foo/bar/test.txt b/configserver/src/test/apps/content/foo/bar/test.txt new file mode 100644 index 00000000000..401a9f6e542 --- /dev/null +++ b/configserver/src/test/apps/content/foo/bar/test.txt @@ -0,0 +1 @@ +bim diff --git a/configserver/src/test/apps/content/foo/test1.json b/configserver/src/test/apps/content/foo/test1.json deleted file mode 100644 index 5716ca5987c..00000000000 --- a/configserver/src/test/apps/content/foo/test1.json +++ /dev/null @@ -1 +0,0 @@ -bar diff --git a/configserver/src/test/apps/content/foo/test1.txt b/configserver/src/test/apps/content/foo/test1.txt new file mode 100644 index 00000000000..5716ca5987c --- /dev/null +++ b/configserver/src/test/apps/content/foo/test1.txt @@ -0,0 +1 @@ +bar diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/ContentHandlerTestBase.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/ContentHandlerTestBase.java index d231c7ac60f..20e52263350 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/ContentHandlerTestBase.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/ContentHandlerTestBase.java @@ -1,16 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http; -import com.google.common.base.Joiner; -import com.google.common.collect.Collections2; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.jdisc.http.HttpRequest; -import org.junit.Test; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; - import static com.yahoo.jdisc.Response.Status.BAD_REQUEST; import static com.yahoo.jdisc.Response.Status.NOT_FOUND; import static com.yahoo.jdisc.Response.Status.OK; @@ -18,21 +8,30 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Test; +import com.google.common.base.Joiner; +import com.google.common.collect.Collections2; +import com.yahoo.container.jdisc.HttpResponse; +import com.yahoo.jdisc.http.HttpRequest; + public abstract class ContentHandlerTestBase extends SessionHandlerTest { protected String baseUrl = "http://foo:1337/application/v2/tenant/default/session/1/content/"; @Test public void require_that_content_can_be_retrieved() throws IOException { assertContent("/test.txt", "foo\n"); - assertContent("/foo/", generateResultArray("foo/bar/", "foo/test1.json", "foo/test2.txt"), "application/json"); - assertContent("/foo", generateResultArray("foo/"), "application/json"); - assertContent("/foo/test1.json", "bar\n", "application/json"); + assertContent("/foo/", generateResultArray("foo/bar/", "foo/test1.txt", "foo/test2.txt")); + assertContent("/foo", generateResultArray("foo/")); + assertContent("/foo/test1.txt", "bar\n"); assertContent("/foo/test2.txt", "baz\n"); - assertContent("/foo/bar/", generateResultArray("foo/bar/file-without-extension", "foo/bar/test.jar"), "application/json"); - assertContent("/foo/bar", generateResultArray("foo/bar/"), "application/json"); - assertContent("/foo/bar/file-without-extension", "content"); - assertContent("/foo/bar/test.jar", "bim\n", "application/java-archive"); - assertContent("/foo/?recursive=true", generateResultArray("foo/bar/", "foo/bar/file-without-extension", "foo/bar/test.jar", "foo/test1.json", "foo/test2.txt"), "application/json"); + assertContent("/foo/bar/", generateResultArray("foo/bar/test.txt")); + assertContent("/foo/bar", generateResultArray("foo/bar/")); + assertContent("/foo/bar/test.txt", "bim\n"); + assertContent("/foo/?recursive=true", generateResultArray("foo/bar/", "foo/bar/test.txt", "foo/test1.txt", "foo/test2.txt")); } @Test @@ -59,27 +58,21 @@ public abstract class ContentHandlerTestBase extends SessionHandlerTest { "{\"status\":\"new\",\"md5\":\"d3b07384d113edec49eaa6238ad5ff00\",\"name\":\"" + baseUrl + "test.txt\"}"); assertStatus("/foo/?return=status", "[{\"status\":\"new\",\"md5\":\"\",\"name\":\"" + baseUrl + "foo/bar\"}," + - "{\"status\":\"new\",\"md5\":\"c157a79031e1c40f85931829bc5fc552\",\"name\":\"" + baseUrl + "foo/test1.json\"}," + + "{\"status\":\"new\",\"md5\":\"c157a79031e1c40f85931829bc5fc552\",\"name\":\"" + baseUrl + "foo/test1.txt\"}," + "{\"status\":\"new\",\"md5\":\"258622b1688250cb619f3c9ccaefb7eb\",\"name\":\"" + baseUrl + "foo/test2.txt\"}]"); assertStatus("/foo/?return=status&recursive=true", "[{\"status\":\"new\",\"md5\":\"\",\"name\":\"" + baseUrl + "foo/bar\"}," + - "{\"status\":\"new\",\"md5\":\"9a0364b9e99bb480dd25e1f0284c8555\",\"name\":\"" + baseUrl + "foo/bar/file-without-extension\"}," + - "{\"status\":\"new\",\"md5\":\"579cae6111b269c0129af36a2243b873\",\"name\":\"" + baseUrl + "foo/bar/test.jar\"}," + - "{\"status\":\"new\",\"md5\":\"c157a79031e1c40f85931829bc5fc552\",\"name\":\"" + baseUrl + "foo/test1.json\"}," + + "{\"status\":\"new\",\"md5\":\"579cae6111b269c0129af36a2243b873\",\"name\":\"" + baseUrl + "foo/bar/test.txt\"}," + + "{\"status\":\"new\",\"md5\":\"c157a79031e1c40f85931829bc5fc552\",\"name\":\"" + baseUrl + "foo/test1.txt\"}," + "{\"status\":\"new\",\"md5\":\"258622b1688250cb619f3c9ccaefb7eb\",\"name\":\"" + baseUrl + "foo/test2.txt\"}]"); } protected void assertContent(String path, String expectedContent) throws IOException { - assertContent(path, expectedContent, HttpResponse.DEFAULT_MIME_TYPE); - } - - protected void assertContent(String path, String expectedContent, String expectedContentType) throws IOException { HttpResponse response = doRequest(HttpRequest.Method.GET, path); assertNotNull(response); final String renderedString = SessionHandlerTest.getRenderedString(response); assertThat(renderedString, response.getStatus(), is(OK)); assertThat(renderedString, is(expectedContent)); - assertThat(response.getContentType(), is(expectedContentType)); } protected void assertStatus(String path, String expectedContent) throws IOException { -- cgit v1.2.3