From: Josef 'Jupp' SCHUGT Date: 2004-02-25T06:21:22+09:00 Subject: Re: OT: mime types and file extensions (was Re: Puzzling...) Hi! * Mark Hubbart: > > On Feb 22, 2004, at 7:25 PM, Trey Campbell wrote: > > >Trying it with the following: > > > >#!C:/ruby/bin/ruby.exe > >print "Content-type: text/plain\n\n" > >print "1st line " > >print "2nd line " > >print "3rd line " > > > >Mozilla renders the page (as if it encountered a
 tag). IE
> >shows a dialog offering to run the associated application (but
> >warning that it might not be a good idea to do so). I wouldn't
> >characterize that as misbehaving since that's what I'd expect it
> >to do, or at least offer to do; it's just doing a better job of
> >recognizing potential helper applications than Mozilla is.
> 
> The mime type is there for a reason. When a file is downloaded, the
> browser is supposed to look at the mime type to figure out what to
> do. If the mime-type is "image/jpeg", that means it's jpeg image,
> despite the fact that it's filename might be "graph.rb" (if it
> happens to be a dynamically created image). A mime type of
> "text/plain" indicates a simple plaintext file, which should be
> rendered on the screen. The browser should NOT try to execute it.

The result can be very surprising. Suppose it's some text document 
about a company's division called 'identification division':

print "Content-type: text/plain\n\n"
puts "      *************************"
puts
puts "       IDENTIFICATION DIVISION."
puts
puts "      *************************"
puts
puts "      * identifies new technologies"
puts
puts "      * gives estimates for return rates we expect"
puts
puts "      * finds the optimal portefeuille for you"


It would be quite surprising to see a window pop up asking if the 
browser should run the COBOL program *SCNR*

> If it should be executed, it should have a mime type of, I don't
> know, "executable/ruby" or something. If the browser can't
> recognize the mime type, *then* it should feel free to try to
> figure it out.

Or leave it to the user.

> A windows pc determines filetypes based on the extension, a mac
> primarily uses the creatorcode and typecode metadata, a unix box
> uses (mostly, i think) magic numbers. All Things Web are supposed
> to use mime types as a bridge. This is to ensure that things like,
> say, a plaintext file, don't get interpreted as, say, an executable
> ruby script.

The Unix solution isn't optimal, either. 'English text' can be a
script in a verbose programming language, an elaborated sed script
may be identified as a 'data', etc.

Josef 'Jupp' SCHUGT
-- 
E-Mail: .--- ..- .--. .--. .--.-. --. -- -..- .-.-.- -.. .
http://oss.erdfunkstelle.de/ruby/    -     German comp.lang.ruby FAQ
http://rubyforge.org/users/jupp/     -     Ruby projects at Rubyforge