@@ -64,6 +64,7 @@ specs = do
6464 it "jsonp" caseJsonp
6565 it "gzip" caseGzip
6666 it "gzip not for MSIE" caseGzipMSIE
67+ it "gzip bypass when precompressed" caseGzipBypassPre
6768 it "defaultCheckMime" caseDefaultCheckMime
6869 it "vhost" caseVhost
6970 it "autohead" caseAutohead
@@ -319,6 +320,14 @@ gzipApp = gzip def $ const $ return $ responseLBS status200
319320 [("Content-Type", "text/plain")]
320321 "test"
321322
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")]
329+ "test"
330+
322331caseGzip :: Assertion
323332caseGzip = flip runSession gzipApp $ do
324333 sres1 <- request defaultRequest
@@ -354,6 +363,14 @@ caseGzipMSIE = flip runSession gzipApp $ do
354363 assertNoHeader "Content-Encoding" sres1
355364 liftIO $ simpleBody sres1 @?= "test"
356365
366+caseGzipBypassPre :: Assertion
367+caseGzipBypassPre = flip runSession gzipPrecompressedApp $ do
368+ sres1 <- request defaultRequest
369+ { requestHeaders = [("Accept-Encoding", "gzip")]
370+ }
371+ assertHeader "Content-Encoding" "gzip" sres1
372+ assertBody "test" sres1 -- the body is not actually compressed
373+
357374vhostApp1, vhostApp2, vhostApp :: Application
358375vhostApp1 = const $ return $ responseLBS status200 [] "app1"
359376vhostApp2 = const $ return $ responseLBS status200 [] "app2"