From c2c4eb471f721f659cbc237f4cc48dc9b946faff Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 12 May 2009 16:40:40 +0000 Subject: [PATCH] Jetty doesn't seem to have a predefined MIME type mapping for JSON. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17993 71c3de6d-444a-0410-be80-ed276b4c234a --- .../org/jvnet/hudson/test/JavaNetReverseProxy.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java b/test/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java index 994f691058..3deb71c834 100644 --- a/test/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java +++ b/test/src/main/java/org/jvnet/hudson/test/JavaNetReverseProxy.java @@ -76,7 +76,7 @@ public class JavaNetReverseProxy extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String path = req.getPathInfo(); + String path = req.getServletPath(); String d = Util.getDigestOf(path); File cache = new File(cacheFolder, d); @@ -85,10 +85,18 @@ public class JavaNetReverseProxy extends HttpServlet { FileUtils.copyURLToFile(url,cache); } - resp.setContentType(getServletContext().getMimeType(path)); + resp.setContentType(getMimeType(path)); IOUtils.copy(new FileInputStream(cache),resp.getOutputStream()); } + private String getMimeType(String path) { + int idx = path.indexOf('?'); + if(idx>=0) + path = path.substring(0,idx); + if(path.endsWith(".json")) return "text/javascript"; + return getServletContext().getMimeType(path); + } + private static volatile JavaNetReverseProxy INSTANCE; /**