@@ -64,6 +64,7 @@ specs = do
64 it "jsonp" caseJsonp
64 it "jsonp" caseJsonp
65 it "gzip" caseGzip
65 it "gzip" caseGzip
66 it "gzip not for MSIE" caseGzipMSIE
66 it "gzip not for MSIE" caseGzipMSIE
67+ it "gzip bypass when precompressed" caseGzipBypassPre
67 it "defaultCheckMime" caseDefaultCheckMime
68 it "defaultCheckMime" caseDefaultCheckMime
68 it "vhost" caseVhost
69 it "vhost" caseVhost
69 it "autohead" caseAutohead
70 it "autohead" caseAutohead
@@ -319,6 +320,14 @@ gzipApp = gzip def $ const $ return $ responseLBS status200
319 [("Content-Type", "text/plain")]
320 [("Content-Type", "text/plain")]
323+-- Lie a little and don't compress the body. This way we test
324+-- that the compression is skipped based on the presence of
325+-- the Content-Encoding header.
326+gzipPrecompressedApp :: Application
327+gzipPrecompressedApp = gzip def $ const $ return $ responseLBS status200
328+ [("Content-Type", "text/plain"), ("Content-Encoding", "gzip")]
322caseGzip :: Assertion
331caseGzip :: Assertion
323caseGzip = flip runSession gzipApp $ do
332caseGzip = flip runSession gzipApp $ do
324 sres1 <- request defaultRequest
333 sres1 <- request defaultRequest
@@ -354,6 +363,14 @@ caseGzipMSIE = flip runSession gzipApp $ do
354 assertNoHeader "Content-Encoding" sres1
363 assertNoHeader "Content-Encoding" sres1
355 liftIO $ simpleBody sres1 @?= "test"
364 liftIO $ simpleBody sres1 @?= "test"
366+caseGzipBypassPre :: Assertion
367+caseGzipBypassPre = flip runSession gzipPrecompressedApp $ do
368+ sres1 <- request defaultRequest
369+ { requestHeaders = [("Accept-Encoding", "gzip")]
371+ assertHeader "Content-Encoding" "gzip" sres1
372+ assertBody "test" sres1 -- the body is not actually compressed
357vhostApp1, vhostApp2, vhostApp :: Application
374vhostApp1, vhostApp2, vhostApp :: Application
358vhostApp1 = const $ return $ responseLBS status200 [] "app1"
375vhostApp1 = const $ return $ responseLBS status200 [] "app1"
359vhostApp2 = const $ return $ responseLBS status200 [] "app2"
376vhostApp2 = const $ return $ responseLBS status200 [] "app2"