title: mod_proxy_ajp error: renders html as text/plain, prompts user to "save as..."
body: <p>We have an odd, intermittent error that occurs with mod_proxy_ajp, i.e. using apache as a front end to a tomcat server.</p>
  
  <p><strong>The error</strong></p>
  
  <ul>
  <li>User clicks on a link browser prompts
  user to "save as...." (e.g. in
  Firefox "You have chosen top open
  thread.jsp which is a
  application/octet-stream"...What
  should firefox do with this file)</li>
  <li>User says "Huh?" and presses "Cancel"</li>
  <li>User clicks again on the same link</li>
  <li>Browser displays the page correctly</li>
  </ul>
  
  <p>This error occurs intermittently, but unfortunately rarely on our test server and frequently on production.</p>
  
  <p>In firefox's LiveHttpHeaders I see the following in the above usecase:</p>
  
  <ul>
  <li>first page download (i.e. click on link) is "text/plain"</li>
  <li>second download is "text/html"</li>
  </ul>
  
  <p>I thought the problem may stem from ProxyPassReverse  (i.e. muddling up whether to use http or ajp), but all these proxypassreverse settings resulted in the same error:</p>
  
  <ul>
  <li>ProxyPassReverse /ajp://localhost:8080/</li>
  <li>ProxyPassReverse /pe <a href="http://localhost/pe" rel="nofollow">http://localhost/pe</a> </li>
  <li>ProxyPassReverse /pe <a href="http://forumstest.company.com/pe" rel="nofollow">http://forumstest.company.com/pe</a></li>
  </ul>
  
  <p>Additionally, I've checked the apache error logs (set to debug) and see no warnings or errors...</p>
  
  <p>** But it works with mod_proxy_http ?? **</p>
  
  <p>It appears that switching to mod_proxy_http 'solves' the problem. Limited testing, I have not been able to recreate the problem in the test environment.</p>
  
  <p>Because the problem is intermittent, I'm not 100% sure that mod_proxy_http "solves" the problem</p>
  
  <p><strong>Environment</strong></p>
  
  <ul>
  <li>Apache 2.2 Windows</li>
  <li>Jboss 4.2.2 back end (tomcat 6)</li>
  </ul>
  
  <p><strong>One other data point</strong></p>
  
  <p>For better or worse, a servlet filter in tomcat gzips the html before sending it to apache. (which means extra work as apache must unzip before it performs ProxyPassReverse's "find and replace").  I don't know if "gzip" messes up.</p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li>anyone seen this before?</li>
  <li>what tools help analyze the cause?</li>
  </ul>
  
  <p>thanks</p>
  
  <p><strong>Addendum 1: Here is the LiveHttpHeaders output</strong> </p>
  
  <p><em>Browser Incorrectly sees html as "text/plain"</em></p>
  
  <pre><code>http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&amp;channelID=1&amp;portalPageId=1002
  
  GET http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&amp;channelID=1&amp;portalPageId=1002 HTTP/1.1
  Host: forums.customer.com
  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-us,en;q=0.5
  Accept-Encoding: gzip,deflate
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Keep-Alive: 115
  Proxy-Connection: keep-alive
  Cookie: __utma=156962862.829309431.1260304144.1297956514.1297958674.234; __utmz=156962862.1296760237.232.50.utmcsr=forumstest.customer.com|utmccn=(referral)|utmcmd=referral|utmcct=/pe/action/forums/displaythread; s_vi=[CS]v1|258F5B88051D3FC3-40000105C056085F[CE]; inqVital=xd|0^sesMgr|{"sID":4,"lsts":1292598007}^incMgr|{"id":"755563420055418864","group":"CHAT","ltt":1292598006741,"sid":"755563549194447187","igds":"1290627502757","exempt":false}^inq|{"customerID":"755562378269271622"}^saleMgr|{"state":"UNSOLD","qDat":{},"sDat":{}}; inqState=sLnd|1^Lnd|{"c":4,"flt":1274728016,"lldt":17869990,"pgs":{"201198":{"c":1,"flt":1274728016,"lldt":0},"0":{"c":3,"flt":1274845009,"lldt":17752997}},"pq":["0","0","0","201198"],"fsld":1274728016697}; adv_search_results_page=10; ep_beta=1; visitorID=57307059; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; __utmc=156962862; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; TLTHID=5CCA50304DE99E28DB79A7B3267D4231; TLTSID=9DFCDE8045B374AAB752CC98A30E8311; AreCookiesEnabled=1; s_cc=true; SC_LINKS=%5B%5BB%5D%5D; s_sq=%5B%5BB%5D%5D; __utmb=156962862.64.10.1297958674; memberexists=T; ev1=greywolf%20hdtv%20whmx
  Cache-Control: max-age=0
  
  HTTP/1.0 200 OK
  Date: Thu, 17 Feb 2011 17:38:42 GMT
  Content-Type: text/plain
  X-Cache: MISS from samus.company.com
  X-Cache-Lookup: MISS from samus.company.com:3128
  Via: 1.0 samus.company.com:3128 (squid/2.6.STABLE20)
  Proxy-Connection: close
  ----------------------------------------------------------
  </code></pre>
  
  <p><em>Browser Correctly sees html as "text/html"</em></p>
  
  <pre><code>http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&amp;channelID=1&amp;portalPageId=1002
  
  GET http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&amp;channelID=1&amp;portalPageId=1002 HTTP/1.1
  Host: forums.customer.com
  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-us,en;q=0.5
  Accept-Encoding: gzip,deflate
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Keep-Alive: 115
  Proxy-Connection: keep-alive
  Cookie: __utma=156962862.829309431.1260304144.1297956514.1297958674.234; __utmz=156962862.1296760237.232.50.utmcsr=forumstest.customer.com|utmccn=(referral)|utmcmd=referral|utmcct=/pe/action/forums/displaythread; s_vi=[CS]v1|258F5B88051D3FC3-40000105C056085F[CE]; inqVital=xd|0^sesMgr|{"sID":4,"lsts":1292598007}^incMgr|{"id":"755563420055418864","group":"CHAT","ltt":1292598006741,"sid":"755563549194447187","igds":"1290627502757","exempt":false}^inq|{"customerID":"755562378269271622"}^saleMgr|{"state":"UNSOLD","qDat":{},"sDat":{}}; inqState=sLnd|1^Lnd|{"c":4,"flt":1274728016,"lldt":17869990,"pgs":{"201198":{"c":1,"flt":1274728016,"lldt":0},"0":{"c":3,"flt":1274845009,"lldt":17752997}},"pq":["0","0","0","201198"],"fsld":1274728016697}; adv_search_results_page=10; ep_beta=1; visitorID=57307059; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; __utmc=156962862; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; TLTHID=5CCA50304DE99E28DB79A7B3267D4231; TLTSID=9DFCDE8045B374AAB752CC98A30E8311; AreCookiesEnabled=1; s_cc=true; SC_LINKS=%5B%5BB%5D%5D; s_sq=%5B%5BB%5D%5D; __utmb=156962862.64.10.1297958674; memberexists=T; ev1=greywolf%20hdtv%20whmx
  Cache-Control: max-age=0
  
  HTTP/1.0 200 OK
  Date: Thu, 17 Feb 2011 17:38:44 GMT
  X-Powered-By: Servlet 2.4; JBoss-4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)/Tomcat-5.5
  Content-Encoding: gzip
  Content-Type: text/html;charset=UTF-8
  Content-Length: 24739
  X-Cache: MISS from samus.company.com
  X-Cache-Lookup: MISS from samus.company.com:3128
  Via: 1.0 samus.company.com:3128 (squid/2.6.STABLE20)
  Proxy-Connection: keep-alive
  ----------------------------------------------------------
  </code></pre>
  
  <p><strong>Addendum 2: Additional Information</strong></p>
  
  <p>The browser did receive the "gzipped" file. I had earlier clicked "save as..." when a few of these errors occurred. Gunzip successfully processed the files and converted them to html.</p>