This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: getting the JDK built-in web server to set the correct mime type
- From: Per Bothner <per at bothner dot com>
- To: alex mitchell <lexaay at gmail dot com>
- Cc: "kawa at sourceware dot org" <kawa at sourceware dot org>
- Date: Wed, 01 May 2013 01:10:27 -0700
- Subject: Re: getting the JDK built-in web server to set the correct mime type
- References: <CDA6B537 dot 4817F%lexaay at gmail dot com>
On 04/30/2013 10:55 PM, alex mitchell wrote:
Hi Per,
No problem, I figured this was probably done some time back so it might be
hard to remember why it was commented out.
I tried re-enabling it, and the first problem was that there is no
variable "context". It might be referring to hctx, but I'm not sure. The
only implementation of getMimeType I could find is in CGIServletWrapper,
which is only a stub:
public String getMimeType (String file) { return null; }
So I'm guessing its commented out because it was not implemented yet.
That sounds right ...
This assumes that the user has a .mime.types file in one of several
possible locations as described here
http://docs.oracle.com/javase/6/docs/api/javax/activation/MimetypesFileType
Map.html, otherwise only a minimal number of mime types are recognized.
The other options that I came across when searching involved using
java.net.URLConnection.guessContentTypeFromName(path) and/or
java.net.URLConnection.guessContentTypeFromStream(resourceStream), but
these seemed to be wrong most of the time.
I'm not sure if this is the best way of doing this. Any suggestions?
I found a webpage suggesting using java.nio.file.Files.html#probeContentType
This does require Java 7.
I'll explore more later.
--
--Per Bothner
per@bothner.com http://per.bothner.com/