THRIFT-1486 Javascript manual testserver not returning content types
Patch: Andrew Grumet

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1228717 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/js/test/build.xml b/lib/js/test/build.xml
index 4409679..f1aa51d 100755
--- a/lib/js/test/build.xml
+++ b/lib/js/test/build.xml
@@ -253,6 +253,7 @@
     <artifact:dependencies filesetId="js.test.dependency.jars">
       <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
       <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
+      <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/>
       <!-- get jstestdriver.jar via maven-->
       <remoteRepository id="jstd-maven-plugin google code repo" url="http://jstd-maven-plugin.googlecode.com/svn/maven2"/>
       <dependency groupId="com.google.jstestdriver" artifactId="maven-jstestdriver-plugin" version="1.3.2.3"/>
diff --git a/lib/js/test/src/test/Httpd.java b/lib/js/test/src/test/Httpd.java
index 0ed051e..f1291d8 100644
--- a/lib/js/test/src/test/Httpd.java
+++ b/lib/js/test/src/test/Httpd.java
@@ -72,6 +72,12 @@
 import thrift.test.ThriftTest;
 import org.apache.thrift.server.ServerTestBase.TestHandler;
 
+import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
+import eu.medsea.mimeutil.MimeUtil2;
+import eu.medsea.mimeutil.MimeType;
+import java.util.Collection;
+import java.util.Iterator;
+
 /**
  * Basic, yet fully functional and spec compliant, HTTP/1.1 file server.
  * <p>
@@ -177,8 +183,20 @@
 
                 } else {
 
+		    String mimeType = "application/octet-stream";
+		    MimeUtil2 mimeUtil = new MimeUtil2();
+		    mimeUtil.registerMimeDetector(ExtensionMimeDetector.class.getName());
+		    Collection<MimeType> collection = mimeUtil.getMimeTypes(file);
+		    Iterator<MimeType> iterator = collection.iterator();
+		    while(iterator.hasNext()) {
+			MimeType mt = iterator.next();
+			mimeType =  mt.getMediaType() + "/" + mt.getSubType();
+			break;
+		    }
+
                     response.setStatusCode(HttpStatus.SC_OK);
-                    FileEntity body = new FileEntity(file, "text/html");
+                    FileEntity body = new FileEntity(file, mimeType);
+                    response.addHeader("Content-Type", mimeType);
                     response.setEntity(body);
                     System.out.println("Serving file " + file.getPath());