Sign in to follow this  
Followers 0
Svetlin Ankov

Apache won't set mime/type correctly

11 posts in this topic

It's a funny thing, but Apache won't set the mime type of jad files correctly.

According to the response from REDbot:


HTTP/1.1 200 OK

Date: Sat, 11 Dec 2010 19:27:40 GMT

ETag: "4d03cd79-318-21a80f4"

Last-Modified: Sat, 11 Dec 2010 19:14:01 GMT

Content-Type: application/octet-stream

Content-Length: 792

Keep-Alive: timeout=2, max=30

Connection: Keep-Alive

The returned type is application/octet-stream. However, it should be text/vnd.sun.j2me.app-descriptor. What's more, the MIME Types page in CPanel shows that the right mime type for jad files is already defined in the list, so what could be wrong? To complicate the situation even more, I'll add that I don't have this kind of problem for jar files, which weren't defined in the list, so I defined their type manually. Here's the response from REDbot:

HTTP/1.1 200 OK

Date: Sat, 11 Dec 2010 19:57:35 GMT

ETag: "4cfbb39f-b3504-21a80ee"

Last-Modified: Sun, 05 Dec 2010 15:45:35 GMT

Content-Type: application/java-archive

Content-Length: 734468

Keep-Alive: timeout=2, max=30

Connection: Keep-Alive

Why do I care? Because the jad file is sometimes needed by mobile devices so that they could then download the jar file, which is my e-book reader app.

Thanks, Eli!

Share this post


Link to post
Share on other sites

I submitted something to cpanel about it but considering Sharad's test works fine, I'm guessing Apache is much better at handeling mime types then Mongrel is. And since mongrel is being used for your content it should have nothing to do with apache right?

Share this post


Link to post
Share on other sites

I envy you, Sharad! It's working fine for you!

I added


AddType text/vnd.sun.j2me.app-descriptor .jad

AddType text/vnd.sun.j2me.app-descriptor jad

to the .htaccess files in /home/albite/public_html and /home/albite/public_html/m (as I am using a subdomain, too), but still came to no avail.

It really seems an absurd problem...

Eli, you are wrong. Apache always comes in the scene. At the very least you know that it's used for the rewrites. Secondly, it's used to serve static content, i.e. anything in my app's public folder, i.e. /home/albite/rails_apps/albite/public/. You can easily see that from the header response for static content, like the .jad files in question, and dynamic content, like the home page.

Thanks a lot to everybody!

Edited by Svetlin Ankov

Share this post


Link to post
Share on other sites

I've decided to skip the JAD files as most phones seem to work fine without them and there is absolutely no problem with setting up the mime type of JAR files.

Eli and Sharad, thank you for your support!

P.S. I hope you like the finished site? It's got more than 2000 books now.

P.P.S. If you by any chance have found a solution for the problem, I'd be more than glad to hear of it despite my decision of dropping the JAD files.

Happy holidays people!

Share this post


Link to post
Share on other sites

Svetlin, what I said is correct. Mongrel is the one setting the mime types for your files.

I manually started your mongrel process with an extra option that defines a mime file.

/usr/bin/ruby /usr/bin/mongrel_rails start -p 12011 -d -e production -P log/mongrel.pid -m /home/albite/mime.mongrel

If you check your file you can see it is now correct.

You might be able to start the command yourself without shell by creating a cron that checks for the process or something and runs the previous mongrel startup line. Maybe..

Share this post


Link to post
Share on other sites

Thank you Eli! You did it!

It turns out you've been right all the time. Well, it seems that the relationship between Mongrel and Apache is yet to be understood by me.

Still, as far as I know, Apache must come into the picture when serving static files, as I've heard Mongrel had some serious limitations there.

Well, I pretty much doubt it I'd be able to start mogrel without the shell. I'd check if I could configure mongrel from within my app though.

Edited by Svetlin Ankov

Share this post


Link to post
Share on other sites

Well, I think it could be done that way:


# Implements a simple DSL for configuring a Mongrel server for your 

# purposes.  More used by framework implementers to setup Mongrel

# how they like, but could be used by regular folks to add more things

# to an existing mongrel configuration.

#

# It is used like this:


  require 'mongrel'

  config = Mongrel::Configurator.new :host => "127.0.0.1" do

    listener :port => 3000 do

      uri "/app", :handler => Mongrel::DirHandler.new(".", load_mime_map("mime.yaml"))

    end

    run

  end

However, as JAR files seem to work just fine, and I don't want to be fiddling with mongrel's config, I'll leave it as it is.

Thanks again!

Share this post


Link to post
Share on other sites

You're probably going to want to do that. I'm going to restart the server sometime soon for a kernel update and once I do your mongrel will go back to before.

Share this post


Link to post
Share on other sites

I had the same problem with epubs. All is fixed now through adding a few lines in an initializer script (e.g. config/initializers/mime_types.rb):


Mongrel::DirHandler::add_mime_type('.epub', 'application/epub+zip')

Mongrel::DirHandler::add_mime_type('.jad', 'text/vnd.sun.j2me.app-descriptor')

Eli, you were completely right about the headers. Java files' headers were right not because I added them to apache's list of mimetypes but because they are listed in Mongrel's default list.

Thanks for your support, you've been very helpful! The site's working perfectly now.

Happy holidays!

Edited by Svetlin Ankov

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0