@@ -29,19 +29,27 @@ ping var app req
2929 return $ responseLBS status200 [] ""
3030 | otherwise = do
3131 res <- app req
32− let renum = responseEnumerator res
33− return $ ResponseEnumerator $ \f -> do
34− renum $ \status headers -> do
35− case lookup "content-type" headers of
36− Just ct
37− | "text/html" `S.isPrefixOf` ct -> do
32+ let isHtml hs =
33+ case lookup "content-type" hs of
34+ Just ct -> "text/html" `S.isPrefixOf` ct
35+ Nothing -> False
36+ case res of
37+ ResponseFile _ hs _ _
38+ | not $ isHtml hs -> return res
39+ ResponseBuilder _ hs _
40+ | not $ isHtml hs -> return res
41+ _ -> do
42+ let renum = responseEnumerator res
43+ return $ ResponseEnumerator $ \f -> renum $ \status headers ->
44+ if isHtml headers
45+ then do
3846 let (isEnc, headers') = fixHeaders id headers
3947 let fixEnc x =
4048 if isEnc
4149 then joinI $ ungzip $$ x
4250 else x
4351 joinI $ builderToByteString $$ fixEnc $ joinI $ insideHead "<script>setInterval(function(){var x;if(window.XMLHttpRequest){x=new XMLHttpRequest();}else{x=new ActiveXObject(\"Microsoft.XMLHTTP\");}x.open(\"GET\",\"/_ping\",false);x.send();},60000)</script>" $$ joinI $ EL.map fromByteString $$ f status headers'
44− _ -> f status headers
52+ else f status headers
4553
4654insideHead :: S.ByteString -> Enumeratee S.ByteString S.ByteString IO a
4755insideHead toInsert =