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