Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Problem with Apache and CGI returning text/plain

 [1/9] from: rebol665::ifrance::com at: 9-May-2002 15:33


Hi rebollers, I am having problem with the following script. 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!d:/rebview/rebol.exe --cgi REBOL [] print "content-type : text/plain^/^/" print "Hello CGI-World!! (text)" 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The script is short but my problem is a bit longer to explain. This script is installed on a windows 98 machine where both Apache and Personal Web Server (PWS) are installed (only one server is active at a time). The script is called with the following URL from another windows 98 machine: http://192.168.1.51/cgi-bin/cgi-hw-txt.r The problem is : - If Apache is running, I am asked to download the file cgi-hw-txt.r. - If PWS is running, all is correct and I am getting the display of "Hello CGI-World!!!(text)" I have investigated a lot ! These are some fact I have gathered : - If I change text/plain for text/html, and if I delete the space in content-type ( "content-type : text/plain" -> "content-type: text/html") then I am getting a response with Apache. - Apache ACCESS.LOG gives me the following trace in both cases : 192.168.1.52 - - [09/May/2002:11:07:34 +0200] "GET /cgi-bin/cgi-hw-txt.r HTTP/1.1" 200 38 As I understand it, the request is OK (200) and returns 38 bytes. - I have made the following function to test the server from the rebol console: cgi-test: does [ pt: open tcp://192.168.1.51:80 insert pt "GET /cgi-bin/cgi-hw-txt.r HTTP/1.0^/^/" print copy pt close pt ] Here are some results : With "content-type : text/plain", download in IE
>> cgi-test
HTTP/1.1 200 OK Date: Thu, 09 May 2002 13:07:15 GMT Server: Apache/1.3.24 (Win32) content-type : text/plain Connection: close Content-Type: text/plain Hello CGI-World!! (text)
>>
With "content-type: text/plain", download in IE
>> cgi-test
HTTP/1.1 200 OK Date: Thu, 09 May 2002 13:09:06 GMT Server: Apache/1.3.24 (Win32) Connection: close Content-Type: text/plain Hello CGI-World!! (text)
>>
With "content-type: text/html", works in IE
>> cgi-test
HTTP/1.1 200 OK Date: Thu, 09 May 2002 13:09:59 GMT Server: Apache/1.3.24 (Win32) Connection: close Content-Type: text/html Hello CGI-World!! (text)
>>
With "content-type : text/html", download in IE
>> cgi-test
HTTP/1.1 200 OK Date: Thu, 09 May 2002 13:11:21 GMT Server: Apache/1.3.24 (Win32) content-type : text/html Connection: close Content-Type: text/plain Hello CGI-World!! (text)
>>
The conclusion here is that the space after "content-type" seems to be very important. With Apache text/plain text/html space after BAD BAD no space BAD OK The same test performed with PWS gives a very different picture. With PWS text/plain text/html space after OK OK no space BAD OK So if I want a script that runs with both PWS and Apache, I must choose text/html and no space after "content-type". However I am still at a loss regarding Apache and text/plain. Has anyone a brilliant idea ? Patrick

 [2/9] from: gscottjones:mchsi at: 9-May-2002 15:17


From: "pat665"
> Hi rebollers, > I am having problem with the following script.
<<quoted lines omitted: 8>>
> Server (PWS) are installed (only one server is active at a time). > The script is called with the following URL from another windows 98
machine:
> http://192.168.1.51/cgi-bin/cgi-hw-txt.r > > The problem is : > - If Apache is running, I am asked to download the file cgi-hw-txt.r. > - If PWS is running, all is correct and I am getting the display of "Hello > CGI-World!!!(text)"
<rest snipped> Hi, Pat, I've grown a bit rusty in Apache configuration, but be sure to set-up http.conf as follows, then restart apache: 1) scriptalias has been set for the cgi-bin directory. Typically uncomment the following #ScriptAlias /cgi-bin/ "C:/Apache/cgi-bin/" to ScriptAlias /cgi-bin/ "C:/Apache/cgi-bin/" 2) Be sure cgi-bin has been set to be executable by setting Options to ExecCGI: <Directory "C:/Apache/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> 3) If you wish to have executable .r files outside of cgi-bin, need to add an AddHandler in the AddHandler section as such: AddHandler cgi-script .r This should be considered a security risk, though. Save the httpd.conf file, then restart Apache. Hope this helps. --Scott Jones

 [3/9] from: rebol665:ifrance at: 10-May-2002 13:26


Hi Scott, I had it all correct except for the "Options ExecCGI" that was "Options none". However the problem with text/plain is not solved. It seems that the browser cannot identify the text/plain type. May be it will be clearer with the help of the proxy.r script suggested by Mike. Patrick

 [4/9] from: gchiu:compkarori at: 11-May-2002 0:09


> However I am still at a loss regarding Apache and > text/plain. Has anyone a > brilliant idea ? >
I didn't read through all the above, but I would suggest using 'open to see the exact headers being sent to you, or use http-tools to do the same. Also, there is this, which may or may not be relevant: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q239750 -- Graham Chiu

 [5/9] from: rebol665:ifrance at: 10-May-2002 15:38


Hi me! I am replying to myself because I have found (at last) an explanation and a solution. "When everything else have failed, try to read the documentation !" Indeed I have found the answer in the Apache FAQ (see below). In brief, IE handles text/plain in a non standard way. The solution is to rename cgi-hw-txt.r to cgi-hw-txt.txt or cgi-hw-txt.cgi . Patrick Apache FAQ Why do my files appear correctly in Internet Explorer, but show up as source or trigger a save window with Netscape; or, Why doesn't Internet Explorer render my text/plain document correctly? MS Internet Explorer (MSIE) and Netscape handle mime type detection in different ways, and therefore will display the document differently. In particular, IE sometimes relies on the file extension or the contents of the file to determine the mime type. This can happen when the server specifies a mime type of application/octet-stream or text/plain. This behavior violates the the HTTP standard and makes it impossible to deliver plain text documents to MSIE clients in some cases. More details are available on MSIE's mime type detection behavior in an MSDN article (http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.a sp) and a note by Alan J. Flavell (http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html). The best you can do as a server administrator is to accurately configure the mime type of your documents by editing the mime.types file or using an AddType directive in the Apache configuration files. In some cases, you may be able to fool MSIE into rendering text/plain documents correctly by assuring they have a .txt filename extension, but this will not work if MSIE thinks the content looks like another file type. Patrick

 [6/9] from: ethanak:interclub:pl at: 10-May-2002 19:27


On May 10 at 13:26 pat665 wrote: Would you put this script somewhere in the Net? I don't think I can help you if I won't see results. Similar script is working OK on my machine (Apache 1.3.20-2) http://mavra.linux.bielsko.pl/cgi-bin/heloreb.cgi ----- #!/usr/local/bin/rebol -c REBOL [] print "Content-Type: text/plain^/" print "Hello, I am the REBOL script" ----- BTW never use spaces before colon in headers (rfc2068)! Namari=EB! ethanak

 [7/9] from: ethanak:interclub:pl at: 11-May-2002 1:17


On May 10 at 19:27 Bohdan R. Rau wrote:
> http://mavra.linux.bielsko.pl/cgi-bin/heloreb.cgi
Sorry - heloreb.r of course! BTW there is one magic line added to headers - does it work on IE? (I have not Windows so I'm not able to check). -- Namari=EB! ethanak

 [8/9] from: rebol665:ifrance at: 11-May-2002 11:04


Hi, Thanks for your script. It works for me too ! My problem was the .r extension of my script. The same script with a .cgi works fine. I have found an explanation for that in the Apache FAQ. For more détails see : (http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html). In brief, it is a "bug" in MSIE with HTTP text/plain document. MSIE do not trust the explicit text/plain content-type and use the file extension instead. In my case, the .r extension caused the CGI results to be downloaded instead of displayed. So I replaced the .r extension with .txt or .cgi. and now it works fine. Patrick ----- Original Message ----- From: "Bohdan R. Rau" <[ethanak--interclub--pl]> To: <[rebol-list--rebol--com]> Sent: Friday, May 10, 2002 7:27 PM Subject: [REBOL] Re: Problem with Apache and CGI returning text/plain On May 10 at 13:26 pat665 wrote: Would you put this script somewhere in the Net? I don't think I can help you if I won't see results. Similar script is working OK on my machine (Apache 1.3.20-2) http://mavra.linux.bielsko.pl/cgi-bin/heloreb.cgi ----- #!/usr/local/bin/rebol -c REBOL [] print "Content-Type: text/plain^/" print "Hello, I am the REBOL script" ----- BTW never use spaces before colon in headers (rfc2068)! Namarië! ethanak

 [9/9] from: g:santilli:tiscalinet:it at: 11-May-2002 11:29


Hi Bohdan, On Saturday, May 11, 2002, 1:17:46 AM, you wrote: BRR> BTW there is one magic line added to headers - does it BRR> work on IE? (I have not Windows so I'm not able to check). You mean Content-Disposition? I just got "Hello, I am the REBOL script" displayed in IE, so I think it's working. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted