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