@@ -8,6 +8,7 @@ import Test.Hspec
9import Network.Wai.Middleware.ForceSSL
9import Network.Wai.Middleware.ForceSSL
11import Data.ByteString (ByteString)
12import Data.ByteString (ByteString)
12import Data.Monoid ((<>))
13import Data.Monoid ((<>))
13import Network.HTTP.Types (methodPost, status200, status301, status307)
14import Network.HTTP.Types (methodPost, status200, status301, status307)
@@ -18,8 +19,12 @@ main :: IO ()
18main = hspec spec
19main = hspec spec
20spec :: Spec
21spec :: Spec
21−spec = describe "forceSSL" $ do
22+spec = describe "forceSSL" (forM_ hosts $ \host -> hostSpec host)
22− let host = "example.com"
23+ where
24+ hosts = ["example.com", "example.com:80", "example.com:8080"]
26+hostSpec :: ByteString -> Spec
27+hostSpec host = describe ("forceSSL on host " <> show host <> "") $ do
24 it "redirects non-https requests to https" $ do
29 it "redirects non-https requests to https" $ do
25 resp <- runApp host forceSSL defaultRequest
30 resp <- runApp host forceSSL defaultRequest
@@ -39,7 +44,7 @@ spec = describe "forceSSL" $ do
40 simpleStatus resp `shouldBe` status200
45 simpleStatus resp `shouldBe` status200
42− it "preserves the original path and query string" $ do
47+ it "preserves the original host, path, and query string" $ do
43 resp <- runApp host forceSSL defaultRequest
48 resp <- runApp host forceSSL defaultRequest
44 { rawPathInfo = "/foo/bar"
49 { rawPathInfo = "/foo/bar"
45 , rawQueryString = "?baz=bat"
50 , rawQueryString = "?baz=bat"
@@ -50,7 +55,6 @@ spec = describe "forceSSL" $ do
51runApp :: ByteString -> Middleware -> Request -> IO SResponse
56runApp :: ByteString -> Middleware -> Request -> IO SResponse
52runApp host mw req = runSession
57runApp host mw req = runSession
53− (request req { requestHeaderHost = Just $ host <> ":80" }) $ mw app
58+ (request req { requestHeaderHost = Just host }) $ mw app
56 app _ respond = respond $ responseLBS status200 [] ""
60 app _ respond = respond $ responseLBS status200 [] ""