tachyon-II has asked for the wisdom of the Perl Monks concerning the following question:

Help. It does not work! :-)

To be precise with perl 5.8.8 and the latest Apache 2.2 on win 32 the following behaviour is observed:

After a default Apache install, using Firefox, browsing to:

http://localhost/cgi-bin/printenv.pl

works as expected and dumps the enironment to the browser. HOWEVER going to the same URL with IE 7 results in the script being downloaded! WTF??? Why is Apache executing the script for Firefox but sending it as a download to IE??? If I make a copy of this default script and rename it .cgi then it works as expected with both Firefox and IE ie http://localhost/cgi-bin/printenv.cgi dumps the env to the browser. Investigations and results (nope = download script to browser, not output)

  1. telnet localhost 80 GET /cgi-bin/printenv.pl HTTP/1.0\n\n -> WORKS as expected (env output)
  2. Remove and reinstal Apache - tried versions 2.0 and 2.2 with and without SSL -> nope
  3. Cleared the IE cache, closed it down, rebooted, tried again - nope
  4. Added a query string http://localhost/cgi-bin/printenv.pl?foo=bar - nope
  5. Added path/info so http://localhost/cgi-bin/printenv.pl/extra/path - WORKS
  6. Accessed via http://127.0.0.1/cgi-bin/printenv.pl - nope
  7. Accessed via http://192.168.1.4/cgi-bin/prinenv.pl - nope
  8. Added and removed (from the appropriate places) with the appropriate apache restart. Note httpd.conf file is vanilla default from fresh install.
    • Options ExecCGI
    • AddHandler cgi-script .pl .cgi

This makes no sense to me. It does not seem to be a caching issue - normally adding a new query string or accessing via a diferent URL will cure this but it does not. As noted I even resorted to a reboot post a cache clean.

Apache should know to execute the script and indeed it does as proven by it working with either telnet or Firefox. Why is it downloading the script to IE? Why does it behave correctly if I add /path/info onto the end?

This is in no way mission critical but I would like to get it to behave.

Update

Thanks to everyone who chipped in. Although it appears to be the perl script being downloaded it is in fact the output of the script. Thanks mwah The issue is the Content-Type: text/plain header which IE is ignoring, choosing instead to try and execute the plain text output as a perl file locally. Changing to text/html fixes the problem. I would really have loved to hear the argument (if there was one) at M$ when some engineer evidently put forward the view that it would be more efficient to ignore the MIME type and take a stab in the dark using some heuristics instead. The link to the M$ article from AM is enlightening. Even if you set the IsTextPlainHonored registry key IE reserves the right to ignore it!

  • Comment on Apache CGI Firefox IE7 Win32 "Bug?" (Solved)

Replies are listed 'Best First'.
Re: Apache CGI Firefox IE7 Win32 "Bug?"
by trwww (Priest) on May 21, 2008 at 10:20 UTC
Re: Apache CGI Firefox IE7 Win32 "Bug?"
by mwah (Hermit) on May 21, 2008 at 10:23 UTC

    Are you sure that IE7 does "save the perl file". This won't happen.

    Maybe it's only a problem w/Mime types, IE7 thinks there is sth. to download (no proper content type sent by the perl script).

    If you give the link a cgi-extension, IE7 might heuristically deduce that the content "should" be html.

    my € 0.02

    mwa

      Now matter how flawed the http header from the browser, Apache should "know better" than to deliver the script. It's got to be some kind of configuration error. I hope.
        Apache should "know better" than to deliver the script. It's got to be some kind of configuration error. I hope

        No way. Apache won't ever send the "Perl script" merely because of a broken browser request. The alleged "Perl script downloaded" will be an empty file or just the normal content saved under the name of the last part of the link.

        I think this post does say all. (Thanks for this one, anonymous).

        Regards

        mwa

Re: Apache CGI Firefox IE7 Win32 "Bug?"
by Anonymous Monk on May 21, 2008 at 10:41 UTC
Re: Apache CGI Firefox IE7 Win32 "Bug?"
by moritz (Cardinal) on May 21, 2008 at 10:07 UTC

    Update: doesn't seem to be an Apache problem, so don't start debugging like I described below.

    I've never heard of such a strange behaviour before.

    There are two things you can do to find out:

    1) Turn on debug level logging for apache. Apache is great in that its logging facilities can be configured in many ways. Try to get as much information as possible. Perhaps it helps.

    2) It sounds like Apache is reacting to some kind of HTTP header. Use a network sniffer like wireshark to record the headers of a request that leads to "not ok" behaviour, and then test them to see which one (or which combination) is the offending.

    Both approaches can be much work, but it's also a great exercise in environment+config debugging ;-)